🎉 All 30 days are live — the full DSA-30 course, from Big-O to System Design. See the roadmap →
Day 29 - Mock InterviewLive Mock Problems

Live Mock Problems

Knowing the framework is one thing; hearing it is another. Below are three problems transcribed the way a strong candidate actually performs them — 🧑‍💼 interviewer and 🧑‍💻 you — across all six phases. Read them out loud. The goal isn’t the solution (you’ve seen these patterns); it’s the narration rhythm between the lines of code.


Mock 1 — Two Sum (warm-up: nail the framework crisply)

🧑‍💼 “Given an array of integers nums and an integer target, return the indices of the two numbers that add up to target.”

CLARIFY

🧑‍💻 “A few questions first. Is there exactly one solution, or could there be none or several? … Exactly one, good. Can I use the same element twice? … No. Are the numbers sorted? … No. Any size or value bounds — could n be up to 10^5? Negative numbers? … Got it: unsorted, one guaranteed answer, no reuse, negatives allowed.”

EXAMPLES

🧑‍💻 “So nums = [2, 7, 11, 15], target = 9[0, 1] since 2 + 7 = 9. Edge cases I’ll keep in mind: the two values being equal like [3, 3], target = 6[0, 1], and negatives like [-1, -8], target = -9.”

APPROACH

🧑‍💻 “Brute force: check every pair — two nested loops, O(n²) time, O(1) space. I can do better. As I scan, for each x I really want to know ‘have I already seen target − x?’ That’s a hash-map lookup — store value → index as I go, and check the complement before inserting. That’s O(n) time, O(n) space. I’ll code the hash-map version — sound good?”

CODE

🧑‍💻 “I’ll keep a map of value to index, scan once, and for each number check if its complement is already in the map.”

TEST

🧑‍💻 “Dry run [2,7,11,15], 9: i=0, need=7, not seen, store {2:0}. i=1, need=2, seen at 0 → return [0,1]. ✓. Edge [3,3], 6: i=0 store {3:0}; i=1 need=3 seen at 0 → [0,1] ✓ — and note I insert after checking, so the same element never pairs with itself.”

COMPLEXITY

🧑‍💻 “O(n) time — single pass, O(1) map operations. O(n) space for the map. That’s the trade vs the O(1)-space, O(n²) brute force — I bought speed with space.”

What scored well here: scoped before coding, stated brute force and its complexity before optimizing, named the trade-off, and — the detail that signals real care — explained why the insert comes after the check (to avoid pairing an element with itself). That one sentence shows you’ve actually thought about correctness, not just pattern-matched. Full template in Day 2 / hashing.


Mock 2 — Longest Substring Without Repeating Characters (medium: brute → optimal)

🧑‍💼 “Given a string s, find the length of the longest substring with no repeating characters.”

CLARIFY & EXAMPLES

🧑‍💻 “Substring meaning contiguous, not subsequence? … Contiguous, good. What’s the character set — ASCII, lowercase, Unicode? … Assume ASCII. Empty string returns 0? … Yes. Example: 'abcabcbb'3 ('abc'). 'bbbb'1. 'pwwkew'3 ('wke', not the non-contiguous 'pwke'). Empty ''0.”

APPROACH

🧑‍💻 “Brute force: check every substring for uniqueness — O(n²) substrings times O(n) to check = O(n³), or O(n²) with a set. Too slow. The repeated work is re-scanning overlapping windows. This is a sliding window: expand a right pointer, and when I hit a duplicate, shrink the left pointer past the previous occurrence. I’ll track each char’s last index in a map so I can jump left directly. O(n) time.”

CODE

TEST & COMPLEXITY

🧑‍💻 “Trace 'pwwkew': r=0 ‘p’ best=1; r=1 ‘w’ best=2; r=2 ‘w’ seen at 1 ≥ left → left=2, best stays 2; r=3 ‘k’ best=2; r=4 ‘e’ best=3; r=5 ‘w’ seen at 2 but 2 < left(2)? it’s equal so left=3, best=3. Returns 3 ✓. Empty string → loop never runs → 0 ✓. The last[c] >= left guard matters — without it a stale occurrence outside the window would wrongly move left backward.”

🧑‍💻 “O(n) time — each index advances right once and left only forward. O(min(n, alphabet)) space for the map.”

What scored well: named the brute force and why it’s wasteful (“re-scanning overlapping windows”), then named the pattern out loud — sliding window — before coding. The killer detail in testing: explaining the >= left guard, which is the exact bug most people ship. See Day 24 — Sliding Window.


Mock 3 — Course Schedule (medium: an ambiguous prompt that’s secretly a graph)

🧑‍💼 “You have numCourses courses and a list of prerequisite pairs [a, b] meaning you must take b before a. Can you finish all courses?”

CLARIFY — the insight is recognizing the structure

🧑‍💻 “Let me reframe to check my understanding: courses are nodes, and [a, b] is a directed edge b → a (‘b unlocks a’). ‘Can I finish all courses’ means — is there an ordering with no circular dependency? So this is really: does this directed graph have a cycle? If there’s a cycle, it’s impossible; otherwise a valid order exists. Can prerequisites be empty? … Yes, then trivially true. Could there be duplicate edges? … I’ll assume possibly, and it won’t affect correctness.”

🧑‍💼 “That’s exactly right.”

APPROACH

🧑‍💻 “Two standard ways: Kahn’s algorithm (BFS topological sort — repeatedly remove zero-indegree nodes; if I can’t remove all, there’s a cycle), or DFS with three-color marking (cycle = back-edge to a node currently on the recursion stack). I’ll do Kahn’s — it’s iterative, no stack-overflow risk, and the count-based cycle check is clean. O(V + E).”

CODE

TEST & COMPLEXITY

🧑‍💻 “Test numCourses=2, [[1,0]]: edge 0→1, indeg=[0,1], queue starts [0], take 0 → indeg[1]→0 → take 1, taken=2==2 → true ✓. Cycle case [[1,0],[0,1]]: indeg=[1,1], queue empty at start, taken=0≠2 → false ✓. Empty prereqs → every node indeg 0 → all taken → true ✓.”

🧑‍💻 “O(V + E) — build the graph in O(E), each node enqueued once, each edge relaxed once. O(V + E) space.”

What scored well: the whole problem turned on the first 60 seconds — recognizing a word problem as cycle detection in a directed graph. Restating the prompt in graph terms (“nodes, edges, is there a cycle?”) is what unlocked it, and the interviewer confirmed it. Then: offered two valid approaches and justified the choice. See Day 23 — Topological Sort.


The pattern across all three

The first move is always translation

Two Sum → “have I seen the complement?”; Longest Substring → “sliding window with last-seen indices”; Course Schedule → “cycle detection.” Strong candidates spend the opening converting the prompt into a known pattern out loud.

Brute force is stated, never skipped

Every transcript names the naive solution and its complexity before optimizing. It anchors the conversation, guarantees partial credit, and shows the interviewer your optimization is deliberate, not lucky.

The bug is caught in TEST, by you

The >= left guard, the insert-after-check, the empty-input case — each was surfaced by tracing the code, not by the interviewer. That’s the single most repeatable way to turn a Hire into a Strong Hire.

Quick check

In Mock 3 (Course Schedule), what was the actual hard part of the problem?
Across all three mocks, the candidate caught their own bugs during TEST (the >= left guard, insert-after-check). Why does this matter so much to interviewers?

Next: The Behavioral Round — STAR, an interactive answer builder, and Leadership-Principle mapping.