Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

numbers =
target =

Codey

Practise coding problems, test your solutions and track your progress.

Explore

  • Problems
  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

© 2026 Codey. Personal learning project.

Solution
Updated: 2026-02-23

Idea

Because the array is sorted, use two pointers from both ends.

Approach

Start l at 0 and r at n-1. If numbers[l] + numbers[r] is too small, increment l; if too large, decrement r. When equal, return 1-indexed indices.

Why it works

Moving the left pointer increases the sum; moving the right pointer decreases it. Sorted order makes these moves correct.

Code
Loading...
Complexity
Time: O(n)
Space: O(1)
Solution
Updated: 2026-02-23

Idea

Because the array is sorted, use two pointers from both ends.

Approach

Start l at 0 and r at n-1. If numbers[l] + numbers[r] is too small, increment l; if too large, decrement r. When equal, return 1-indexed indices.

Why it works

Moving the left pointer increases the sum; moving the right pointer decreases it. Sorted order makes these moves correct.

Code
Loading...
Complexity
Time: O(n)
Space: O(1)