A classic interview problem: given an array of numbers and a target, find 2 different numbers that add up to the target and return their indexes. For example, in [2, 7, 11, 15] with target 9, the answer is indexes 0 and 1, because 2 + 7 = 9. It tests whether you know how to swap a linear search for a hash table lookup.
The fast solution walks the array just once with a hash table storing each number seen and its index. For each number, its complement, target minus the number, is looked up in the table. If it's there, that's the answer. If not, the current number is stored and the walk continues. Each table lookup is O(1), so everything is O(n) in time, in exchange for O(n) memory.
The same idea works for many problems: instead of searching for something by walking everything each time, what's been seen is kept in a hash table and checked in O(1). Finding duplicates, counting frequencies, checking whether 2 lists share elements or grouping words with the same letters are all variants of the same pattern.
The first solution is to try every pair: one loop walks each number, and another loop inside walks the ones after it, checking whether they add up to the target. That's 2 nested loops: O(n²) in time, and O(1) in memory, because it stores nothing extra. With 10,000 numbers that's about 50 million pairs: very slow.
This problem shows trading space for time: the hash table uses O(n) extra memory and in exchange drops the time from O(n²) to O(n). Even though it uses more memory, it's the best solution, because the time-space balance is much better. In many algorithm problems, swapping a linear search for a hash lookup lowers the complexity.
If the array is already sorted, there's another solution that uses no extra memory: 2 pointers, one at the start and one at the end. If their sum is less than the target, the left one moves forward, to make it bigger; if it's more, the right one moves back. Each step discards an element: O(n) in time and O(1) in memory. If the array isn't sorted, sorting costs O(n log n) and the hash table is the better choice.