The brute force approach checks every pair. That's because you have two nested loops. But think about it differently. For each number , you're looking for . If you could check whether exists in constant time, you'd only need one pass. What data structure gives you lookup? A hash map. Store each number as you iterate. Before storing, check if its complement already exists.
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
$ curl repovive.com/roadmaps/maang-interview-prep/arrays-hashing/two-sum-hint
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████████████████████████████████████████████████████████████████████████