Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

nums =
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

Use a hash map from value to index to find the needed complement in O(1) average time.

Approach

Scan the array. For each number x, compute target - x. If the complement was seen before, return the pair of indices.

Why it works

When you reach index i, every earlier value is already stored, so you can detect the unique valid pair as soon as the second element is processed.

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

Idea

Use a hash map from value to index to find the needed complement in O(1) average time.

Approach

Scan the array. For each number x, compute target - x. If the complement was seen before, return the pair of indices.

Why it works

When you reach index i, every earlier value is already stored, so you can detect the unique valid pair as soon as the second element is processed.

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