Create an empty hash map
For each element arr[i]: compute complement = target - arr[i]
If complement exists in map, return [map[complement], i]
Otherwise, store arr[i] -> i in map
One loop. O(1) lookups. Total: O(n).
(Single pass with map)
Create an empty hash map
For each element arr[i]: compute complement = target - arr[i]
If complement exists in map, return [map[complement], i]
Otherwise, store arr[i] -> i in map
One loop. O(1) lookups. Total: O(n).