Lab 07 — Stuck Recovery
Goal
Train the explicit “stuck protocol” so that when you don’t see the optimal in an interview, you don’t freeze — you systematically work through a checklist that has a high chance of unblocking you within 3 minutes.
Background Concepts
- The 11-step stuck protocol (see FRAMEWORK.md)
- The difference between productive struggle and unproductive freeze
- How to ask for a hint without losing the interview
Interview Context
Every candidate gets stuck. The signal in your favor is how you respond. A candidate who gets stuck and applies a visible recovery protocol is a strong signal. A candidate who gets stuck and goes silent is a weak signal regardless of whether they recover.
Problem Statement
Three problems below are deliberately chosen to be above what you can solve cold without a known pattern. For each:
- Apply the 11-step stuck protocol explicitly, narrating each step
- Time-cap each step at 60 seconds
- If you’ve used 8+ steps without progress, ask for a hint (in this lab, “ask for a hint” means: read the hint section at the bottom)
- Continue until solved
- Document which step generated the breakthrough
Problems (medium-difficulty, but you don’t have the pattern yet):
- Container With Most Water: given heights, find two indices
i, jsuch thatmin(h[i], h[j]) * (j - i)is maximum. - Longest Palindromic Substring: find the longest palindromic substring of a string.
- Search In Rotated Sorted Array: given a sorted array rotated at an unknown pivot, find target in O(log N).
(If you already know all 3 cold, replace with 3 unfamiliar mediums.)
Constraints
Standard. Assume N ≤ 10^5.
Clarifying Questions
For each problem, list 3 you’d ask the interviewer.
Examples
Construct 3 examples for each.
Initial Brute Force
For each problem, write the O(N^2) brute force first.
Brute Force Complexity
State.
Optimization Path — Apply The Stuck Protocol
The 11 steps in order:
- Restate the problem. Out loud, in your own words.
- Write the brute force. It is correct, even if slow.
- Examine the constraints. What does N suggest?
- Construct smaller examples. Solve N=2, N=3 by hand.
- Look for repeated work. What does the brute force recompute?
- Look for sortedness or monotonicity. Could sorting help? Is something monotonic?
- Look for symmetry / pattern from a known DS family. Two-pointer? Sliding window? Heap?
- Try graph modeling. Some non-graph problems become BFS/DFS when you reframe.
- Try a math approach. Closed form? Modular arithmetic? Combinatorial identity?
- State the simplest approach you have. Even if not optimal — get it down.
- Ask for a nudge. Phrase: “I’ve explored A, B, and C. I think the answer might involve D-family of approaches but I’m not seeing it cleanly. Could you nudge me?”
Final Expected Approach
For each problem, the recovery protocol leads to:
-
Container With Most Water: Two pointers from both ends, moving the smaller one inward. Step 7 (two-pointer pattern) gets you there. Loop invariant: the optimal answer doesn’t include any pair
(L, R)we’ve already discarded. -
Longest Palindromic Substring: Either expand-around-center (step 4 — by hand on N=3,4,5 you spot the center idea) or DP (step 5 — repeated work on overlapping substrings). Manacher’s is optimal but step 4/5 is enough.
-
Search In Rotated Sorted Array: Modified binary search. Step 6 — “is something monotonic?” — at least one half is sorted. Use that to decide which half to recurse into.
Data Structures Used
- Two pointers (#1)
- Center expansion / DP table (#2)
- Modified binary search (#3)
Correctness Argument
For each, the post-recovery solution has a clear correctness argument:
- The “moving the smaller one” strategy is correct because moving the larger pointer cannot increase
min(h[i], h[j])(still bounded by the smaller) and reduces width. - Center-expansion enumerates every (center, length) pair exactly once.
- The half that is sorted contains target iff
targetis in[lo, mid](or[mid, hi]); otherwise recurse on the other half.
Complexity
- O(N) time, O(1) space
- O(N^2) time (center expansion); Manacher’s is O(N)
- O(log N) time, O(1) space
Implementation Requirements
For each problem, after applying the protocol, implement it and run tests. The deliverable is the protocol log + working code.
Tests
- Smoke: given example
- Edge: N=0, N=1, N=2
- Adversarial: all-equal heights (#1), all-same-char string (#2), no rotation (#3 with sorted input)
- Random: 50 small random inputs vs brute
Follow-up Questions
- “Why didn’t you see the optimal immediately?” — be honest: “I hadn’t internalized the two-pointer pattern yet” or “I tried sweeping linearly and missed the symmetry.”
- “What pattern would you check next time?” — internalize the answer.
- “When would you fail to recognize this in an interview?” — when nervous, or when the problem is wrapped in unfamiliar context.
Product Extension
In production, “stuck on a bug” follows the same shape: restate symptom, find a minimal reproduction, narrow the search, hypothesize cause, verify by experiment, ask a teammate. The protocol generalizes.
Language/Runtime Follow-ups
- Python: for #2, naive O(N^2) center expansion may TLE on
N = 10^5due to constant factors; consider Manacher’s for full credit - Java:
String.substringin older versions copies; in newer versions it shares — beware version differences - C++: raw character arrays beat
std::stringfor hot loops
Common Bugs
- Stuck protocol going too fast — you skip step 4 (small examples) and miss the breakthrough that lives there
- Stuck protocol going too slow — you spend 5 minutes on step 5 instead of moving on
- Not asking for a hint when 11 steps are exhausted (rare, but happens — pride costs the interview)
- Asking for a hint too early (before step 6) — looks weak
Debugging Strategy
If your protocol runs took >15 minutes per problem, you spent too long per step. Cap individual steps at 60 seconds; if no progress, move on.
If you finished without a hint, congratulations — but verify that you didn’t already know the pattern, in which case use a different problem.
Deliverable
- Per-problem stuck protocol log: for each of the 3 problems, a written record of which step you tried, how long, what you tried, did it advance you?
- The breakthrough step annotated.
- Working implementation + tests for each problem.
- Reflection: which 2 steps are weakest for you? (e.g., many candidates skip step 4 — small examples — because it feels too elementary, but it’s often the highest-yield step.)
Mastery Criteria
- Solved all 3 problems with explicit protocol use
- Spent ≤ 15 min per problem (including coding + tests)
- Identified the breakthrough step accurately
- Used at most 1 hint across the 3 problems
- Identified your two weakest protocol steps
- Re-attempted with the weak steps as starting points and noticed faster progress
Hints (peek only after attempting)
Container With Most Water hint: “Think about what happens at the two extreme ends — and which pointer moving inward could possibly improve the answer.”
Longest Palindrome hint: “Every palindrome has a center. How many possible centers are there?”
Search In Rotated Sorted Array hint: “Even though the full array is rotated, one half across any midpoint must be sorted. Can you tell which half?”