Mock 03 — Medium LeetCode

Interview type: Standard LC medium — the modal interview question type Target role: SWE-I → SWE-II, generic mid-tier phone screen Time limit: 35 minutes Format: 1 medium problem Hints policy: One free hint at 15 min; additional -2 each Primary goal: Pattern recognition under time pressure + clean implementation.


What This Mock Tests

Mediums are the bread and butter of coding interviews. If you can’t pass mediums consistently in 30–35 min, you cannot pass FAANG. The bar is:

  • Recognize the pattern (sliding window, hashmap, two pointers, BFS, etc.) within 5 minutes
  • State optimal complexity before coding
  • Implement correctly with clean code
  • Test 3+ cases including 1 non-obvious edge

Scoring weights this mock equally across all dimensions, with slight emphasis on Optimization (#4) and Testing (#8) — these are the differentiators at the medium level.


Pick One Problem

Problem A — Longest Substring Without Repeating Characters (LC 3)

Given a string s, find the length of the longest substring with no repeating characters.

Examples:

"abcabcbb"  → 3   ("abc")
"bbbbb"     → 1   ("b")
"pwwkew"    → 3   ("wke")
""          → 0

Constraints: 0 ≤ |s| ≤ 5×10^4. Printable ASCII or English letters/digits/symbols.

Problem B — Group Anagrams (LC 49)

Given an array of strings, group anagrams together. Return any order.

Examples:

["eat","tea","tan","ate","nat","bat"]
→ [["bat"],["nat","tan"],["ate","eat","tea"]]

[""]    → [[""]]
["a"]   → [["a"]]

Constraints: 1 ≤ |strs| ≤ 10^4. 0 ≤ |strs[i]| ≤ 100. Lowercase English letters.

Problem C — Coin Change (LC 322)

Given coin denominations coins and an amount, return the fewest number of coins needed. If impossible, return -1. Infinite supply of each coin.

Examples:

coins = [1, 2, 5], amount = 11   → 3   (5 + 5 + 1)
coins = [2],       amount = 3    → -1
coins = [1],       amount = 0    → 0

Constraints: 1 ≤ |coins| ≤ 12. 1 ≤ coins[i] ≤ 2^31 - 1. 0 ≤ amount ≤ 10^4.


Expected Communication Style

  1. Restate in your own words; explicitly state the input/output types.
  2. Ask 3–5 clarifying questions: input bounds, edge cases, output ambiguities.
  3. State brute force with complexity.
  4. Name the pattern. (“Sliding window over a hashmap” / “Hash group by sorted string” / “Unbounded knapsack DP.”)
  5. State optimal complexity before coding.
  6. Code with narration. Pause briefly at decision points (e.g., “I need to evict from the window — let me use a map of char→last_seen_index instead of a set, so I can jump the left pointer”).
  7. Test 3+ cases, including 1 designed to break common bugs.

Solution Sketches

A. Longest Substring: sliding window with hashmap (char → last index seen). When duplicate enters, advance left to max(left, last_seen[c] + 1). O(N) time, O(min(N, alphabet)) space.

B. Group Anagrams: key by sorted string, OR key by char-count tuple. Hashmap from key → list of strings. O(N · K log K) for sort key, O(N · K) for count key.

C. Coin Change: DP. dp[i] = min coins for amount i. dp[i] = min(dp[i - c] + 1) for c in coins. O(amount × |coins|) time.


Common Failure Modes

  1. For A: used a set + slide, but O(N²) worst case. Need the hashmap-with-last-index trick to keep O(N).
  2. For A: forgot the max(left, ...) when jumping the left pointer. Causes left to move backwards on out-of-window duplicates.
  3. For B: used sorted string as key but the sort is O(K log K) per word. Acceptable, but count tuple is O(K). Discuss the tradeoff.
  4. For C: greedy approach (always pick the largest coin). Wrong on coins = [1, 3, 4], amount = 6: greedy gives 4+1+1 = 3 coins; DP gives 3+3 = 2.
  5. For C: forgot to initialize dp[0] = 0 or to handle amount = 0.
  6. For C: didn’t check if i - c >= 0 before lookup. Causes IndexError or wrong answer.

Passing Bar

  • Total score: 42/70 (average 3.0)
  • Optimal complexity reached
  • Correct on all given examples + at least 1 self-generated edge case
  • Hint usage ≤ 1
  • Time: ≤ 35 min

Follow-up Questions

For A:

  • Return the substring itself, not just length. → Track start position in addition to max length.
  • What if “repeating” means within a window of K positions? → Modify the window logic; same approach.
  • Unicode? → Use codepoint, not byte; alphabet might be huge so use hashmap, not array.

For B:

  • What if strings can be huge (1M chars)? → Hashing the count tuple becomes the bottleneck; consider streaming Rabin-Karp.
  • Anagram detection in a stream? → Maintain rolling count.
  • Approximate anagrams (with one letter difference)? → Locality-sensitive hashing.

For C:

  • Return the actual coin combination, not just the count. → Track parent pointer in DP; reconstruct.
  • Number of ways to make change. → Different DP: dp[i] = sum of dp[i-c].
  • What if coin counts are limited? → Bounded knapsack variant; O(amount × sum(counts)).
  • Why doesn’t greedy work? → Coin systems where greedy works are “canonical” (e.g., USD coins); others (e.g., [1, 3, 4]) require DP.

Required Tests

For all:

  • Given examples
  • Empty input (where legal)
  • Single-element / minimum input
  • Input that triggers the pattern’s worst case (e.g., for A: "aaaaa"; for C: amount=0 and impossible amount)
  • A randomly chosen non-trivial case you verify by hand

Required Complexity Explanation

State:

  • Time complexity, with the bottleneck identified
  • Space complexity, including auxiliary data structures
  • Whether the bound is tight or improvable

Self-Evaluation Template

Mock 03 — Medium LC
Date: _______
Problem: _______
Time: ___ / 35 min
Hints used: ___

Scores (1–5) for all 14 dimensions:
___ Total /70

Pattern recognized in: _____ minutes
Bug count during coding: ___
Bug count caught by my own tests: ___

Strongest dimension:
Weakest dimension:
Specific drill for next session:

What to Do If You Fail

  • Score 35–41: Repeat with a different problem; focus on weak dimension.
  • Took > 35 min: You need more medium volume. Solve 20 mediums in the next week against a 35-min timer.
  • Couldn’t recognize the pattern: Go back to Phase 2 (patterns) README and re-read the signal table.
  • Bug-prone code: Phase 10, Lab 02 (TDD) and Lab 05 (stress testing).
  • Communication weak: Record yourself; listen back; identify silent stretches.
  • Pass twice in a row before moving to Mock 04.