Module 0 · Lesson 4 · ~20 min
FAANG DSA interviews are not blind problem-solving — they're narrated problem-solving. Interviewers want to hear the same five-act structure every time. Once you've internalized it, half the cognitive load disappears, because you always know what move comes next.
1. Clarify the problem. 2. Brute force a working solution. 3. Optimize with a better algorithm. 4. Code it, narrating as you type. 5. Test it on edge cases.
Every act has a vocabulary that signals competence. Let's go through them in order.
Almost every interview problem is intentionally underspecified. The interviewer is checking: do you assume, or do you ask?
The five questions to fire off, every time:
[2, 7, 11, 15], target 9 → [0, 1] because nums[0] + nums[1] = 9. Got it."Ask all five in the first minute. It costs you nothing and signals "I am a senior engineer who would never ship code based on assumptions."
Always describe a brute-force solution before writing the optimal one. Reasons:
The pattern: "The brute force is to enumerate every (thing) and check (condition). That's O(X) time and O(Y) space. We can do better."
This is where the interviewer is actually evaluating you. Don't jump to the answer — talk through why the brute force is wasteful, and what you'd trade to avoid it.
A few patterns the optimization usually takes:
| If brute force is… | Common move | Phrase to use |
|---|---|---|
| Repeating lookups | Precompute a hash map | "Trade O(n) space to make lookups O(1)." |
| Recomputing same subproblem | Memoize / DP | "Cache subresults — collapse the call tree." |
| Comparing every pair | Sort + two pointers | "If we sort first, we can sweep with two pointers." |
| Searching unsorted | Sort + binary search | "Sort upfront; pay O(n log n) once for O(log n) queries." |
| Repeated max/min | Heap | "Maintain a heap so the next max is O(log n)." |
| Sliding-range computation | Sliding window | "Move the window incrementally instead of recomputing each step." |
You don't need to memorize all of these — by the end of the course they'll be reflexive. But the shape of the move ("trade A for B") is the language you should always use.
Don't write code in silence. Talk through every variable: "i is a left pointer, j is a right pointer, total is the running sum." Two reasons:
Style notes that matter:
seen, complement, left, right — never x, y, z.When the code looks done, don't say "done" — say "let me trace through it."
Pick a small input, walk through your code line by line, narrate the values of every variable. Then specifically check:
Finding your own bug during this walk-through is better than not having one. It demonstrates the same instinct senior engineers use in code review.
"My final solution runs in O(X) time, O(Y) space. The brute force was O(X′); we improved it by (precomputing / sorting / using a heap / using a two-pointer sweep). The trade-off is (extra space / one-time sort cost). Edge cases I checked: (empty / dup / single). I think it handles all the cases — should we look at any others?"
Memorize the structure. Customize the words. By the end of this course it'll come out of your mouth without thinking.
Here's how the five acts look on the most cliché interview problem in existence. Read it as a script — you say everything in italics out loud.
Interviewer: Given an integer array nums and an integer target, return the indices of two numbers such that they add up to target.
You (Act 1, Clarify):
"Quick clarifications. The numbers — integers, can they be negative? [yes] Can the array contain duplicates? [yes] If multiple pairs sum to target, do I return any one, or all? [any one] Is there always exactly one answer? [yes] Output is the two indices? [yes] Empty array assumption — never empty, length at least 2?"
You (Act 2, Brute):
"Brute force: nested loop, check every pair. That's O(n²) time, O(1) space. Works but quadratic."
You (Act 3, Optimize):
"The wasted work in the brute force is rescanning the array for each i. We can trade O(n) space for O(1) lookup. As I scan i from 0 to n-1, I keep a hash map of value → index for everything I've already seen. For each nums[i], I look up complement = target - nums[i] in the map. If it's there, I'm done. If not, store nums[i] → i and continue."
You (Act 4, Code):
def two_sum(nums, target):
seen = {} # value → index
for i, x in enumerate(nums):
c = target - x # complement
if c in seen:
return [seen[c], i]
seen[x] = i
return [] # contract says always one answer; defensive return
You (Act 5, Test):
"Trace [2, 7, 11, 15], target 9. i=0, x=2, c=7, seen={}, store 2→0. i=1, x=7, c=2, c is in seen as index 0, return [0, 1]. Correct. Edge cases: duplicates — [3, 3], target 6: i=0, store 3→0. i=1, c=3, c in seen, return [0, 1]. Correct. Negatives — [−1, 0, 1], target 0: i=0, store −1→0. i=1, c=0, no. store 0→1. i=2, c=−1, c in seen, return [0, 2]. Correct."
You (Cheat sentence):
"Final: O(n) time, O(n) space. Brute force was O(n²); we traded O(n) space to make lookups O(1). The hash map is the workhorse. Edge cases: duplicates and negatives both handled. Want me to dig into anything?"
That's the rhythm. Every problem in the rest of this course is going to push you toward this script.