Given a 1-indexed array of integers already sorted in non-decreasing order, find two numbers that add up to a target value and return their indices (1-indexed), using only O(1) extra space.
numbers = [2,7,11,15], target = 9[1,2]numbers = [2,3,4], target = 6[1,3]Solve it in the editor. Sign in free to run your Python or JavaScript against test cases, get a verdict, and track your attempts.
Solve on FeatCode →Two indices move through a sorted (or sortable) structure — often from opposite ends or at different speeds — to avoid the nested loops a brute-force scan would need.
Read the full Two Pointers guide →
Original problem on LeetCode ↗