Lesson 25 of 30
You don't need to have seen a problem before to solve it. You need a repeatable process — and this lesson hands you one.
12 min read
Every option explains itself — why the right one is right, and why each wrong one is wrong. Miss one and it comes back later on a spaced-repetition schedule.
This topic is about judgment and practical tradeoffs more than a single right answer — a mock interview is the better way to test yourself on it.
Be interviewed on this →Hints without spoilers, and a plain explanation of why a wrong answer was wrong — answered only from this lesson. Free account, no card.
Sign up freeWhat interviewers actually ask about this, and what a strong answer has to cover.
A strong answer covers
Likely follow-ups
Think about how a good cook handles a recipe they've never made. They don't panic — they read it, gather ingredients, taste as they go, and adjust. They have a process that works no matter the dish.
Most people walk into a DSA interview hoping they've seen the exact question before. That's fragile — you can't memorize every problem. What works instead is a small process you run every time, seen before or not. Here it is, in six steps:
This is, honestly, the single most valuable thing in this track. Patterns like two pointers or hash maps are tools. This framework is what tells you when to reach for which one, on a problem you've never met before.
// Problem: "Given an array of numbers, find the largest gap between
// any two numbers that appear in increasing order (left one smaller)."
// Step 1: restate it. "Find two numbers, left one smaller than right
// one, where (right - left) is as big as possible."
// Step 2: small example by hand. [3, 8, 1, 9]
// Pairs where left < right: (3,8)=5, (3,9)=6, (1,9)=8. Biggest gap: 8.
// Step 3: brute force. Check every pair. Slow, but obviously correct.
function largestGapBruteForce(nums) {
let best = 0;
for (let i = 0; i < nums.length; i++) {
for (let j = i + 1; j < nums.length; j++) {
if (nums[i] < nums[j]) {
best = Math.max(best, nums[j] - nums[i]); // keep the biggest gap seen
}
}
}
return best;
}
// Step 6 (testing step 3 early): largestGapBruteForce([3, 8, 1, 9]) -> 8. Matches!
Every pattern earlier in this track — two pointers, sliding window, hash maps for instant lookup — is a specific answer to step 4: "how do I speed up the brute force?" This framework gets you there on a problem none of those lessons covered directly.