Weak-Pattern Intensive
Take the bottom three patterns from the L59 audit and repair them with the rebuild loop: blind template, three costumes, interleaved re-test.
Original publication date unrecordedUpdated
Lesson preparation & details
Level: advanced
By the end, you should be able to
- Practice timing, company labels and readiness scores are self-assessment conventions, not validated hiring-frequency or success predictions
Bring with you
Sources checked: . A source check does not change the publication or update date.
Editorial review: · What review means
In this article · 18 sections
Review boundary and corrected contracts
Learning objective: Use L59's evidence to practise up to three weak patterns: derive their state and invariants, compare different problem variants, write cue cards, and check unaided retrieval both immediately and after a delay.
The schedule is a practice design, not a guaranteed repair. An immediate pass shows immediate performance, not durable mastery. The window function below is retained with a precise contract; it is not a universal solution to every contiguous-subarray task. Company-frequency claims are not part of the problem bank.
Series: LeetCode — From Basics to Production-Ready · Session 60 / 65 · Phase 4 · Design review simulation
Watch first
Use the actual failed attempt to choose what to review. Optional historical resources from the original lesson are NeetCode on practice, CS Dojo's problem-solving tips and freeCodeCamp's DP course. Their content and durations have not been freshly verified; they are not evidence for an optimal learning schedule. If DP is the gap, select a relevant state-definition example, not an entire course by default.
Attempt the derivation before consulting a reference, then use the reference to diagnose the exact missing step. Reading can teach unfamiliar material; retrieval practice is not a reason to withhold needed instruction indefinitely.
Why this session exists
L59 proposes weak mechanisms; this session tests a targeted response. Spreading 60 minutes uniformly over 28 families gives each about 2.14 minutes, whereas focusing on three gives each 20. That arithmetic explains concentration of attention, not a guaranteed learning gain or employer outcome. The value depends on which gaps matter to your goals and what the practice actually changes.
“Practise more windows” is too vague. “Explain when a discarded left endpoint can never become useful again, then test three contracts” identifies the work. Use the original failed input, a proof attempt and an independent check to decide whether the gap is retrieval, concept, representation or implementation.
Blank-file warm-up
Spend five minutes attempting your two weakest templates without notes. Save even an incomplete attempt as the baseline, with the invariant you intended. This is a pre-check, not warming up for an unseen assessment.
If the L59 evidence is missing or stale, quickly recheck the proposed patterns before investing in a full repair. A pattern you have never learned needs instruction and worked examples, not a test of recall you cannot yet have.
Pattern anatomy
The rebuild loop has four activities: re-derive, compare three variants, write a cue card, then re-test. Remove scaffolding where the exercise calls for retrieval, but use feedback to repair a failed derivation.
Suggested 80-minute session, including the pre-check:
0–5 Save two unaided baseline attempts.
5–25 Pattern A: 5 min derivation, 12 min variant attempts, 3 min cue card.
25–45 Pattern B: same three activities.
45–65 Pattern C: same three activities.
65–80 Shared interleaved re-test: 5 minutes per pattern in mixed order.
During derivation: try first; then inspect the missing step and close the notes.
During variants: first may use a reference; attempt the others without it.
During re-test: hide cue cards, select/justify the pattern, then reconstruct it.
Afterwards: schedule a separate delayed check, for example in two days.This resolves an ordering problem: a cross-pattern re-test should come after all three repair blocks, not demand repaired templates B and C during A's first block. Each pattern receives 25 minutes across the session; the five-minute pre-check is additional. If variants need longer, repair fewer patterns or schedule more time—three full Medium/Hard implementations in twelve minutes is not an established expectation.
Interleaving asks you to select among patterns rather than reuse the immediately preceding one. That is the purpose of the mixed check. Its difficulty is not proof of improved retention, and it need not outperform blocked practice for every learner or task.
The cue
Use this intensive when a recent attempt identifies a mechanism you have learned but cannot reliably reconstruct, especially when a similar failure appears in both a mock and the audit. Repeated evidence strengthens a repair hypothesis; it does not prove its cause.
Avoidance can suggest what to inspect, but preference alone is not a diagnosis. Prioritise by your own prerequisite needs and planned tasks rather than asserting that sliding windows appear constantly at employers and segment trees almost never do. If the failure is unfamiliarity, return to instruction; if it is a single coding defect, a smaller regression exercise may suffice.
Guided solve
Suppose sliding-window validity is the measured gap.
Step 1 — re-derive. For the following longest valid routine, state contains positive counts of the hashable values in the inclusive window [left, right]. Including the new item can make it invalid; shrinking restores validity. Validity is asserted after the while, not throughout expansion or shrinking.
The predicate must be pure and total for count dictionaries, must accept the empty window, and must be hereditary under taking contiguous subwindows: a subwindow of a valid window is valid. Equivalently, an invalid window cannot become valid just by extending it. Examples are “at most k distinct values” for nonnegative k and “no repeated values.” The predicate must depend only on the represented counts; an order-sensitive constraint needs different state.
def longest_valid_window(arr, condition_holds):
left = 0
best = 0
state = {} # whatever the condition needs
for right, x in enumerate(arr):
# 1. include x in state
state[x] = state.get(x, 0) + 1
# 2. shrink while the window is INVALID
while not condition_holds(state):
y = arr[left]
state[y] -= 1
if state[y] == 0:
del state[y]
left += 1
# 3. window is valid here -> update answer
best = max(best, right - left + 1)
return bestWhy this original algorithm works under that contract. Before updating best, the counts match the window and the predicate holds. Every smaller start that the loop discarded gave an invalid window when discarded. Heredity means that extending that invalid window cannot restore validity, so those starts remain unusable at later right endpoints. The loop therefore stops at the earliest feasible start for this right endpoint, giving the longest valid window ending there. Maximising those lengths gives the global longest length. Empty-window acceptance ensures shrinking stops by left = right + 1; an empty input returns 0. This proof does not apply to an arbitrary predicate.
For arr = [1, 2, 1, 3] and lambda counts: len(counts) <= 2, the first three items give best length 3. Adding 3 produces three distinct values. Removing the first 1 leaves another 1, so it is still invalid; removing 2 restores validity with [1, 3]. The final answer remains 3, not the final window's length 2. Deleting zero counts is necessary because len(state) is meant to count distinct values actually present.
Counterexample to the unrestricted template claim. Let the predicate be “sum at most 0” and allow negative values. On [2, -2], the routine discards [2], then returns 1 for [-2]; the true longest valid window is the full array of length 2. The predicate accepts the empty window, but validity is not hereditary: a valid [2, -2] contains invalid [2]. Future negative values can rescue a discarded start. This is a contract violation, not evidence that the preserved algorithm is wrong for at-most-k-distinct.
Step 2 — three variants. Compare longest substring without repetition, minimum window substring, and maximum consecutive ones with at most k flips. They share moving endpoints, not one interchangeable invariant. The first fits this longest-window contract with counts at most one. The third fits a zero-count budget. Minimum coverage is different: expand until coverage holds, record a candidate while valid, then shrink until coverage breaks. Merely moving best into the existing invalid-window loop does not solve it. Derive its coverage state and stopping condition separately.
Spend the twelve-minute block on bounded attempts, traces and invariant comparisons; finish full implementations later if needed. For each, name what would make your previous variant's proof fail.
Step 3 — cue card. Example in your own words: “Use this longest-window routine when the contract is contiguous, count-maintainable and hereditary. After shrinking, the earliest feasible start gives the longest valid window ending at right; best is the largest length seen, not necessarily the current length.” A shortest-cover card must state its different validity/update rule.
Step 4 — shared mixed re-test. After all selected repair blocks, hide the cards, mix the problem cues and reconstruct each relevant template and proof. Record incorrect selections as well as code errors. If a pattern still fails, save the exact missing concept and revisit its original lesson before another attempt; extending a tired session is not the only option.
Solo timed
The variant block is a twelve-minute attempt budget, not a promise of three completed solutions. Pick smaller cases or fewer families when needed.
- DP: if the observed failure is state definition, use one worked implementation and write the meanings of candidate states for several other tasks. If transitions or base cases failed instead, target those.
- Backtracking: check choose/explore/unchoose and whether successful as well as failed paths restore shared state when the contract requires it.
- Monotonic stack: justify comparison direction and duplicate handling. Indices are needed when distance or width matters; storing values is not universally wrong.
- Graphs: distinguish adjacency construction, traversal state and termination. A representation error needs a different drill from an incorrect BFS invariant.
Timing rubric
| Activity per pattern | Budget | Evidence to keep |
|---|---|---|
| Re-derive | 5 min | Initial attempt, missing invariant, corrected derivation |
| Three variant attempts | 12 min | Different contracts, traces and unresolved work |
| Cue card | 3 min | Trigger, state, invariant and a disqualifying case |
| Mixed re-test, after all blocks | 5 min | Unaided selection, code and proof attempt |
Three patterns use 75 minutes, plus the five-minute pre-check: 80 minutes. Stop an activity at its budget and record what remains. A smaller completed repair with a delayed check may be more useful than claiming all three passed after skipping their tests. The time cap is adjustable, but compare like conditions when interpreting results.
Self-scoring checklist
Score each pattern after the shared re-test, not before the other blocks:
- 0 — incomplete: could not reconstruct the required invariant/template. Review the specific concept, then retry.
- 1 — scaffolded: needed notes or a cue. Record what the cue supplied.
- 2 — unaided with correction: reconstructed it and caught an error through a trace or test.
- 3 — unaided and checked: selected the right variant, justified its invariant and passed the chosen checks.
These are labels for this attempt, not validated mastery levels. All four scores get a delayed check, for example in two days. A 3 does not skip directly to a 21-day interval, and a 0 may need instruction before retesting. Immediate speed alone does not remove a pattern from the weak list.
Problem bank by pattern
Choose contrasts, not company tags. The links identify exercises; the grouping is a teaching choice, not evidence of frequency at an employer. A family can contain different algorithms and proof obligations.
- Sliding window: Longest Substring Without Repeating Characters (3), Minimum Window Substring (76), Max Consecutive Ones III (1004). Compare longest-valid and shortest-cover invariants explicitly.
- Two pointers: 3Sum (15), Container With Most Water (11), Trapping Rain Water (42). Sorting, endpoint elimination and height bounds have distinct correctness arguments.
- Monotonic stack: Daily Temperatures (739), Largest Rectangle in Histogram (84), Next Greater Element II (503). Compare unresolved queries, width boundaries and circular traversal.
- Backtracking: Subsets (78), Word Search (79), N-Queens (51). Identify the choice state, constraints and undo contract.
- DP: House Robber (198), Coin Change (322), Longest Increasing Subsequence (300). State each cell's meaning; these are not one recurrence, and some have non-DP alternatives.
- Graphs: Number of Islands (200), Course Schedule (207), Rotting Oranges (994). Contrast component discovery, dependency-cycle detection and multi-source shortest arrival time.
- Heap/top-K and scheduling: Kth Largest Element in an Array (215), Merge k Sorted Lists (23), Task Scheduler (621). State what the heap orders and why; a heap is an option, not mandatory for every listed problem.
Common failure modes
Reading first removes the unaided baseline; it does not make reading useless. Three near-identical exercises test less variation than three contrasting contracts, but they can still teach implementation. Blocking and mixing answer different practice needs; mix the closing test to inspect selection among the repaired patterns.
Misconception: “Polishing strengths is always better because those are what I will use.” You do not fully control future tasks, so known gaps deserve attention. But the converse claim—that the weakest pattern determines all outcomes—is also false. Expected performance depends on task mix, capabilities and improvement costs, not just the minimum score. Use your measured gaps and goals to allocate practice without inventing an employer distribution.
The cue card should explain a rule you can defend. Paraphrasing visible notes is not necessarily retrieval; close them and reconstruct the rule, then check it. Keep the mixed re-test and delayed check distinct: one tests immediate unaided performance; the other adds evidence about retention. Neither guarantees permanence or transfer to unseen variants.
Complexity
For the window code, right advances n times and left advances at most n times. There are at most 2n predicate evaluations: one stopping evaluation per outer iteration plus one for each removal. With expected O(1) dictionary operations and an O(1) predicate, total expected time is O(n); space is O(d), where d is the maximum number of distinct keys retained, at most n. For at most k distinct values, transient state can contain k+1 distinct values before shrinking. Non-mutating predicates are required so this state argument remains valid.
If the callback scans all d counts, include that cost: O(nD) in the worst case, where D is the largest distinct-state size. “No repeated values” expressed as all(count <= 1 for count in counts.values()) is valid but not automatically a linear-time implementation. A dedicated duplicate counter can give a cheaper predicate. This routine returns a length, not a witness, and does not mutate the input array.
Session cost is 80 minutes under the suggested allocation. Delayed checks add time. A two-day check followed by a seven-day check is a starting schedule, not a guarantee that forgetting begins or ends on those dates.
Self-check (answer follows each question).
Q: Why try a derivation before opening notes?
A: It reveals what you can retrieve unaided and what is missing. Then use corrective feedback; a failed attempt alone does not guarantee consolidation, and unfamiliar material may require instruction first.
Q: Why choose visibly different variants?
A: They test whether you can identify the shared mechanism and the limits of its proof. Explain which invariant changes rather than copying a skeleton because the problems share a label.
Q: What is interleaving, and must it feel worse or always work better?
A: It mixes patterns instead of completing only one family at a time. Here it tests choosing among methods after scaffolding is removed. Difficulty and retention benefits vary; neither discomfort nor an immediate pass proves durable learning.
Q: Why limit the session to three patterns rather than five?
A: Under this budget each gets 20 minutes of repair plus five of mixed checking. Five such allocations need 125 minutes before setup. Choose fewer patterns or a longer session instead of silently dropping the checks.
Q: Why write the cue card in your own words?
A: Reconstructing it without notes exposes whether you can explain the trigger and invariant. Merely paraphrasing visible text is not a retrieval test; compare your card with the reference afterwards.
Q: You pass immediately but fail in L61 two days later. What follows?
A: The immediate result did not establish durable or transferable performance. Compare the actual failed condition: delayed retrieval, a different variant, implementation or pressure may be involved. Revisit the missing mechanism and schedule another unaided delayed check, rather than diagnosing working memory as the sole cause.
Recovery scripts
Template absent: “This asks about a contiguous range, but that alone does not justify a window. I need a state and a proof that discarded starts cannot become useful again.”
Details missing: “I will write a small correct baseline and use it to test the proposed faster rule.” State its cost and limits.
Approach fails: “This counterexample violates my assumption. Sorting is an option only if changing order preserves the contract; otherwise I need different state.”
Nothing arrives: restate the input/output and trace one concrete input aloud. These are tools for making the reasoning visible, not promises about how a reviewer will grade it.
Checkpoint
You can now plan the four activities with a shared closing mixed test; attempt an unaided derivation before consulting notes; compare contrasting variants; write a trigger/invariant/disqualifier card; score the observed attempt; schedule a delayed check; and recover from a missing template by returning to the contract and baseline.
For the window example, additionally explain why empty-window acceptance ensures termination, why hereditary validity justifies discarding starts, why best can exceed the final window length and when callback cost changes the time bound.
Spaced queue
Record every attempt and its assistance level. Re-test each selected pattern unaided in about 2 days. After a successful delayed check, schedule another in 7 days, then adjust the usual ladder (cold +60d, warm +21d, hint +7d, failed +2d then +7d) to actual retention. An unsuccessful check calls for diagnosis and feedback before repetition.
Update the L59 table without overwriting its baseline. Immediate improvement, delayed retrieval and transfer to a new problem are separate evidence. The deliverable is a tested explanation and a next check, not a declaration that the weakest three are permanently fixed.
Executable practice boundary
Use hashable items and a pure count predicate accepting the empty state and satisfying the hereditary contract. For example, lambda counts: len(counts) <= 2 returns the longest range with at most two distinct values. A predicate rejecting empty can shrink beyond the input; a non-hereditary one such as signed sum at most zero can discard a later-optimal start. Both are outside this function's supported contract. The original algorithm is retained; the added proof narrows the claim to what it actually computes.
Corrective source notes
The saved 2026-10-07 APS summary of the learning-techniques review was re-read. It supports practice testing and distributed practice across the reviewed educational settings, not universal interleaving superiority, an exact calendar, company-frequency claims or guaranteed hiring outcomes. The window proof and counterexample are derived in this lesson and checked against the actual displayed function; finite tests supplement, rather than replace, the contract argument.
Pause / Recall / Apply
Can you explain it without the page?
Close the example. Reconstruct the core idea, then change one assumption. Mark complete when you’re ready; you can always undo it.
Stored in this browser only. No account, no sync. Clearing browser data removes your record.