Data Structures & Algorithms using JavaScript
/Intermediate
Two Sum Sorted
Definition
If an array is strictly sorted, Two Sum can be solved in O(1) space by placing one pointer at `index 0` and one at `index N-1`. If `sum < target`, increment left. If `sum > target`, decrement right.
Explain Like I'm New
Since it's sorted, if your guess is too low, move the left finger to the right to get a bigger number. If it's too high, move the right finger to the left to get a smaller number.
Interactive Coding Challenges
Identify the core logic required to implement Two Sum Sorted.
Solution Code
Loading...
Console output will appear here...