Two Sum II
intermediateFinds two indices in a sorted array that sum to a target using opposite-end two pointers; O(n) time, O(1) space.
TARGET18
L
R
2
[0]7
[1]11
[2]15
[3]19
[4]23
[5]2+23=25?18
L=0R=5sumtarget
Initialising pointers…
Two pointers: L at index 0, R at index 5. Looking for two numbers that add up to 18.
1 / 10