Module 0 · Lesson 4 · ~20 min

The interview pattern — clarify, brute, optimize, code, test

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.

The five acts

The 5-act structure

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.

Act 1 — Clarify (the 60-second move)

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:

  1. Input shape and size. "Are these integers? Could they be negative? Is the array sorted? How big — 100? 10⁹?"
  2. Edge cases. "What if the input is empty? What if it has duplicates? What if it has just one element?"
  3. Output. "Should I return the indices or the values? What if there's no answer — return -1, return null, raise?"
  4. Constraints. "Should I optimize for time, space, or readability? Is there a memory limit?"
  5. Examples. "Let me work through this on a small case: [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."

Act 2 — Brute force (the safety net)

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."

Act 3 — Optimize (the moment that signals seniority)

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 movePhrase to use
Repeating lookupsPrecompute a hash map"Trade O(n) space to make lookups O(1)."
Recomputing same subproblemMemoize / DP"Cache subresults — collapse the call tree."
Comparing every pairSort + two pointers"If we sort first, we can sweep with two pointers."
Searching unsortedSort + binary search"Sort upfront; pay O(n log n) once for O(log n) queries."
Repeated max/minHeap"Maintain a heap so the next max is O(log n)."
Sliding-range computationSliding 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.

Act 4 — Code (narrate every line)

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:

Act 5 — Test (the closing move)

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.

The cheat sentence — your closing line

Practice this closing

"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.

The full thing in one example — Two Sum

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.

Notebook prompt — this is the big one