Given an array of integers nums and an integer target, return indices of the two numbers that add up to target. You may assume exactly one solution exists, and you may not use the same element twice.
nums = [2,7,11,15], target = 9[0,1]A HashMap gives O(1) average-case lookup. For every element we check whether its complement already exists — meaning we've previously seen the other number that would complete the sum. If found, we immediately have both indices. If not, we record the current number for future lookups. This single pass eliminates the need for a brute-force O(n²) nested loop.