โœ๏ธ

Two Sum II (Sorted Input)

Easy๐Ÿท๏ธ Two pointers๐Ÿ“‚ Two Pointers & Sliding Window
๐Ÿงฉ The problem

The array is sorted in increasing order. Return the 1-based positions [i, j] of the two numbers that add up to the target, using O(1) extra space.

Examples

  • [2, 7, 11, 15], 9 โ†’ [1, 2]

๐ŸŽฏ Aim for: O(n) time ยท O(1) space

โœ๏ธ Write your solution

Pick a language, press Run to try it, then Run tests to check it against every test case โ€” just like a coding interview.

โ† All practice problems