Skip to content

Instantly share code, notes, and snippets.

@ankitwww
Last active February 22, 2021 15:40
Show Gist options
  • Save ankitwww/4230a3dcb10ae24b9de467afaff5eb6b to your computer and use it in GitHub Desktop.
Save ankitwww/4230a3dcb10ae24b9de467afaff5eb6b to your computer and use it in GitHub Desktop.

[Don't comment your code here - You will be immediately disqualified]

Given an array of sorted numbers and a target sum, find a pair in the array whose sum is equal to the given target.

Write a function to return the indices of the two numbers (i.e. the pair) such that they add up to the given target.

Example 1:

Input: [1, 2, 3, 4, 6], target=6 Output: [1, 3] Explanation: The numbers at index 1 and 3 add up to 6: 2+4=6

Example 2:

Input: [2, 5, 9, 11], target=11 Output: [0, 2] Explanation: The numbers at index 0 and 2 add up to 11: 2+9=11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment