We’re given an input array of numbers that are sorted in non-decreasing order. Our function should return the indices (1-indexed) of two numbers that satisfy the target.
Example
Approach 1
This problem is really similar to a regular two sum. We just need to ensure we make the index change by adding one to the index. To solve this we can use a two pointer method which are defined as the left and right pointers. Based on the current sum that we derive we either increase the left index or decrease the right index. Increase the left index means we’ll derive a greater sum, while decreasing the right index we’ll derive a smaller sum.