Two Sum
Easy
arrays
Google
Amazon
Meta
Python Editor
Output
Click "Run Code" to see results...
Use a hash map to store each number's index as you iterate. For each number, check if its complement (target - current) is already in the map. This gives O(n) time instead of O(n²) with brute force.