nums and an integer target, return the indices of
the
two numbers that add up to target. Assume exactly one solution exists, and you cannot use
the
same element twice.
| Strategy | Time | Space | Key Idea / Trade-offs |
|---|---|---|---|
| Brute Force | O(n²) | O(1) | Checks every pair. Simple, zero added memory, inefficient on large datasets. |
| AI 1 — Hash Map | O(n) | O(n) | Single pass. Stores seen values to instantly find complement in O(1) time. |
| AI 2 — Two Pointers | O(n log n) | O(n) | Sorts elements with original indices, then shrinks inward using two pointers. |