1Two Sum: find two numbers that add up to a target.
Brute force: check every pair, O(n²) time.
Optimal: one pass with a hash map from value to index. For each number, check whether target - x was already seen.
def two_sum(nums, target):
seen = {}
for i, x in enumerate(nums):
if target - x in seen:
return [seen[target - x], i]
seen[x] = iO(n) time, O(n) space. If the array is sorted (or you may sort it and don't need original indices), two pointers give O(1) extra space. Follow-ups: 3Sum (sort + fix one element + two pointers, O(n²)), counting pairs, handling duplicates.