Two Sum (Unsorted)

Hash Maps · medium

Given an **unsorted** array `nums` and a `target`, return the 0-based indices `[i, j]` (i < j) of the two numbers that add up to `target`. Exactly one solution exists. Example: `twoSumUnsorted([2, 7, 11, 15], 9)` → `[0, 1]`.

Hints
  • Use a hash map to store each number's index as you scan.
  • For each number, check if its complement (target − number) is already in the map.

Learning resources

Loading...

Run your code to see results.