FAANG · LeetCode #1
Two Sum — three-stage drill
1The ProblemEasy
Two Sum
Return indices of the two numbers that add up to a target.
Examples
[3,2,4], target=6→ [1,2][3,2,4], target=10→ none
constraintExactly one solution; can't use the same element twice.
2The PatternTIME O(n) · SPACE O(n)
Arrays & Hashing
Trade space for time: a hash map turns 'have I seen this?' into an O(1) lookup.
Problems using this pattern
3The SolutionRESULT → [1, 2]
Step through it
seen = {} (value → index). target = 6
Step 1 / 4
Arrow keys to navigate · escape to reset