Two that add up, in a sorted list

A code exercise of about 15 minutes: read the statement, solve «Two that add up, in a sorted list» in the browser and get a review like in a real interview.

Code · 15 min
Loading…

Statement

Write pairSumSorted(sorted, target): sorted is in ascending order. Return the indices [i, j] (with i < j) of two numbers that add up to target, or [] if there are none. If there are several pairs, the one with the smallest i and, for that i, the largest j. This time without a map: O(1) memory.