twoSum()You have a $9 gift card. On the belt are prices [2, 7, 11, 15]. At index 0 you see $2; you need $7 (9 - 2), so you scribble "Saw $2 at index 0" on your sticky note. Next you see $7 at index 1. You glance at your sticky note: "Aha! I already saw $2 at index 0!" You return [0, 1] immediately!
Target is 9. Partner needed = 9 - 2 = 7. Notepad is empty! Record { 2: index 0 } on notepad.
### The Mission You are holding a gift voucher worth an exact target balance (e.g. **$9**). You walk along a supermarket conveyor belt where items with prices are rolling past in an array: `[2, 7, 11, 15]`. Your mission is to find the **two item positions (indices)** whose combined prices sum up to exactly your gift voucher. ### Why You Can't Just Use Two Loops Checking every pair with nested loops takes **O(N²)** time — if the conveyor belt has 100,000 items, the store closes before you finish! Instead, use a **Memory Notepad (Hash Map)**: as you inspect each item, calculate what partner price you need (`target - price`). If you've already seen that partner, you win instantly in **O(N)** time!