Arrays and hash maps

Given a comma-separated list of integers and a target number, find the indices of the two numbers that add up to the target. Print them space-separated (lower index first).

Assume exactly one solution always exists.

Input:  2,7,11,15 9
Output: 0 1

The numbers at index 0 (2) and index 1 (7) sum to 9.


Constraints

  • Return the lower index first.
  • You may not use the same element twice.
  • Aim for O(n) — use a hash map.
Ad SpaceGoogle AdSense active for guests & free-tier learners.