Lesson 3 of 3
How to practice so it sticks
Rereading a solution feels like learning, but writing it again from memory keeps more. This lesson turns that idea and five more from the research into a weekly routine, shows where the lab runs each one for you, and lays out a 16 to 20 week plan.
Work through new code in five steps: predict, run, investigate, modify and make
Decide what to do when a problem has beaten you for 30 minutes
Work out the day a solved problem is due again on the re-solve ladder
Sort a miss into one of four types and find the type to drill next
Lay out a practice week and the 16 to 20 week plan for a fundamentals restart
Yesterday you got the largest-number loop working with the solution open beside you. Tonight you have 45 minutes. You could read that solution again until every line feels familiar. Or you could close it, open a blank editor, try to write it, and watch yourself stall on the second line.
The blank editor is the choice that sticks. It feels worse and works better. Each section below takes one idea from the research behind this lab, makes it a routine, and shows where the lab runs it for you. The last section lays out the plan for a fundamentals restart (coming back to interview coding after years away): 16 to 20 weeks.
Predict, run, investigate, modify, make
What should you do the first time you meet a piece of code? Every lesson in this lab follows the same five steps, a sequence from school computing called PRIMM (Sentance and colleagues, 2019):
- Predict: read the code and say what it will do before you run it.
- Run: run it (here, step through its trace) and compare the result with your guess.
- Investigate: ask the code questions. What is the notebook (the values the code keeps as it goes)? Which line changes it? What is always true about it?
- Modify: change one thing and predict again.
- Make: write something like it from a blank editor.
A wrong prediction is the most useful thing the five steps turn up. Step through the trace to the first line where the values differ from your guess: that is the line you misread, and the one to learn. A study of beginning programmers (Lopez and colleagues, 2008) found that the students who could trace code and explain it in plain words also tended to write code well. Reading code is part of the skill, not a warm-up before it.
Try the five steps on a program about practice itself. It reads a week of practice minutes, Monday to Sunday, and counts the days with any practice at all. Predict first.
This program reads a week of practice minutes, Monday to Sunday. Type exactly what it prints.
minutes = [50, 45, 0, 60, 55, 200, 0]
sessions = 0
for m in minutes:
if m > 0:
sessions += 1
print(sessions)
Now run it. The trace below shows the code on the left and every name and value on the right. Press Next to move one line at a time, and keep your eye on the notebook, sessions.
minutes = [50, 45, 0, 60, 55, 200, 0]sessions = 0for m in minutes:if m > 0:sessions += 1print(sessions)
(nothing printed yet)Investigating means asking the code questions and checking each answer against the trace. What is the notebook? One count, sessions. Which line changes it? Only line 5. What is true about it after every pass? It equals the number of visited days that had any practice. That sentence is the promise from the previous lesson: a fact about the notebook that is true after every pass. When the walk ends every day has been visited, so the promise is the answer. Here are all four answers of the frame:
Modify comes next: change one thing and predict again. Say you only want the long sessions, the days with at least 60 minutes. Only the test changes: m > 0 becomes a check for 60 or more. Predict first: how many days in the week above qualify? Then build that version, written as a function that returns the count, from its shuffled lines.
Put the lines in order to build long_sessions(minutes), which counts the days with at least 60 minutes of practice. Indentation is already part of each line. Two of the lines do not belong.
Add lines from the list below, in order.
if m >= 60:count = 0for m in minutes:return countdef long_sessions(minutes):if m > 0:count += 1if m > 60:
Make is the blank editor: a code exercise or a problem where you write the code yourself. The previous lesson had two, and every module has problems. Do not skip straight to make: the predictions are where you find out what you do not know yet.
Write it from memory, not from the page
You solved a problem with help. What should you do with it next: reread the solution, or close it and write it again?
Rereading feels better. The code looks familiar, every line makes sense, and familiar feels like known. But recognizing a solution is a different act from producing one, and the interview asks you to produce. Producing it means retrieval: pulling something out of your own memory instead of reading it again. In a study by Roediger and Karpicke (2006), people who practiced recalling material remembered about 61% of it a week later, and people who reread it remembered about 40%. Retrieval beats rereading.
One honest caveat, which also covers the spacing and mixing studies below: almost all of this evidence is about remembering facts. That it carries over to solving new problems under pressure is a reasonable bet, not a measured result.
In practice, retrieval means a blank editor. After you solve a problem here, it opens with its blank starter the next time, not with your old code. Writing it again is slower than reading it, and it shows you exactly which step you could not rebuild.
How long should you fight a problem before you look? The research digest (the course's summary of interview research, from the first lesson) sets a limit, the struggle cap: 20 to 35 minutes of genuine attempt, then read the approach, and re-solve it from scratch on a later day. The approach is the problem's plan in words: its walk, notebook, promise and cost, with no code. A genuine attempt is work you can point to: a brute force (the slow, obvious solution) written down, an example traced by hand, a notebook tried and dropped. Staring at the prompt does not count.
Both ends of that range matter. Open the approach at minute 3 and you never tried to produce anything yourself. Grind for two hours and one problem eats the evening. Reading the approach after a real attempt is not cheating: the re-solve from a blank editor, on a later day, is the step that counts.
Each problem page here shows a target time: 15 minutes for an easy problem, 25 for a medium, 40 for a hard. That is how long a solid solve should take, tested and with its cost stated. The cap is for when you are stuck. The page's timer starts when you first edit or run the code, and if it reaches 35 minutes without a solve, a note suggests opening the approach and logging the miss (a later section shows the miss journal).
You have worked on a medium problem for 30 minutes. You wrote a brute force that is too slow, traced two examples by hand, and you still do not see a faster way. What should you do now?
Choose one answer, then check.
Come back on a schedule
When should a solved problem come back? Later, and more than once: spaced practice beats massed practice. Massed means all in one sitting; spaced means spread over days. In a review of memory studies by Cepeda and colleagues (2006), spaced practice beat massed practice in 259 of 271 comparisons.
The research behind this lab turns that into a schedule: re-solve a problem 1, 3, 7 and 14 days after the previous solve, and add a second pass at 30 days during a fundamentals restart. Each gap is longer than the last, so a problem you keep solving comes back less and less often.
This lab runs the schedule as a ladder. A clean solve moves a problem up one rung: every test passes, the solution stays closed, and you use at most one hint (opening the approach counts as one). A re-solve must also take 15 minutes or less (20 for a hard problem). A solve with help sends it back to the bottom: you opened the solution, used two or more hints, or took longer than that on a re-solve. A day when you do not solve it changes nothing: the problem stays due until you do. The gap is counted from the day of the solve:
| Clean solves in a row | Next re-solve |
|---|---|
| 0 (the last solve needed help) | 1 day later |
| 1 | 1 day later |
| 2 | 3 days later |
| 3 | 7 days later |
| 4 | 14 days later |
| 5 | 30 days later |
| 6, the last one in mock mode | Retired: it stops coming back |
Due problems wait on the Today tab of the Practice page. Only one solve a day counts: passing the same problem again that day does not move it. Two rules from the research shape the ladder. A re-solve that takes more than 10 to 15 minutes means the gap was too long, so the lab counts a slower re-solve as one that needed help; the problem page shows how long each solve took. And retire a problem only after a clean re-solve that was also timed and narrated out loud. The lab retires a problem only when its sixth clean solve in a row was done in mock mode (a clock running and no Run button). If the sixth was not, the problem comes back once more, 30 days later, for that mock-mode re-solve. The lab cannot hear you, so narrate that one out loud.
Check the table against your first two days with a problem:
You solve a problem cleanly on day 0 and re-solve it cleanly on day 1. On what day is its next re-solve due? Type the day number.
Type a number: 12, -1, 0.5 and 3/4 all work. Enter checks.
What happens when a solve needs help? Take this history for one problem: clean on day 0, clean on day 1, solved with the solution open on day 4, clean again on day 5. Before you step through, guess the day it is due next.
The function below is a small model of the lab's rule. It leaves out the time limit, the mock-mode rule and retirement, so it handles up to five clean solves in a row. It walks the solves, oldest first, and keeps one number: the streak of clean solves in a row. results holds one True or False per solve (True means clean), and last_day is the day of the latest solve. GAPS is the ladder's list of gaps; a name in capitals is Python's convention for a value the code never changes.
Two pieces of Python are new here. if clean: tests the value of clean itself, so its line runs when clean is True. else: runs its lines when the if test is false, so on every pass exactly one of streak += 1 and streak = 0 runs.
GAPS = [1, 3, 7, 14, 30]def next_due(last_day, results):streak = 0for clean in results:if clean:streak += 1else:streak = 0if streak == 0:return last_day + 1return last_day + GAPS[streak - 1]
(nothing printed yet)One rule carries the whole ladder: a solve with help resets the streak, and only the streak sets the next gap. The two clean solves before day 4 count for nothing on day 5, on purpose: a problem that needed the solution on day 4 was not as solid as the streak said.
Now build the schedule yourself. If every solve is clean and every re-solve happens on its due day, each solve day is the previous one plus the next gap, so the solve days are a running total of the gaps: from day 0, they are 0, 1, 4, 11, 25 and 55. Put the lines in order.
Put the lines in order to build solve_days(first_day, gaps). It returns every day you solve a problem, starting with the first solve, assuming every solve is clean and every re-solve happens on its due day. first_day is the day of the first solve, and gaps lists the waits in order. With the lab's gaps, solve_days(0, [1, 3, 7, 14, 30]) returns [0, 1, 4, 11, 25, 55]. Indentation is already part of each line. Two of the lines do not belong.
days = [day] makes a list holding one item, the value of day. days.append(day) adds the value of day to the end of the list.
Add lines from the list below, in order.
day = first_dayreturn daysfor gap in gaps:def solve_days(first_day, gaps):days.append(gap)days = [day]day = first_day + gapday = day + gapdays.append(day)
So far: predict before you run, write from memory instead of rereading, cap the struggle at 20 to 35 minutes, and let clean re-solves on a growing schedule decide when a problem comes back.
Block first, then mix
In what order should problems come? The answer depends on patterns. A pattern is a standard walk and notebook that solves a whole family of problems. Keeping a set of the numbers already passed, from the previous lesson, is one; later modules teach the others, such as two pointers and the sliding window.
There are two ways to arrange a session. Blocked practice works one pattern at a time: four sliding window problems in a row. Mixed practice (also called interleaved) shuffles problems from different patterns, so each one starts with the question "which pattern is this?"
Blocked practice is the right way to meet a pattern. The research digest recommends 3 to 5 problems back to back per pattern on first exposure. Here, every problem in a module uses what that module's lessons teach, so working a module's problems in a row is blocked practice.
Once you have met each pattern, switch to mixed sets. In a study by Rohrer and Taylor (2007), mixed practice beat blocked practice on a later test. One reason fits interviews closely: in a blocked set you know the pattern before you read the problem, and in an interview you never do. Blocked practice never asks you to choose; mixed practice asks every time.
The Mixed set tab on the Practice page draws a set of 3 to 6 problems (you choose; 4 by default) from the modules you have started, spread across as many patterns as it can. Before you open each one, read the statement and name the pattern out loud.
You read the sliding window lesson today and solved its first problem. What should your next practice session hold?
Choose one answer, then check.
Name every miss
When a problem beats you, why did it? "I got it wrong" does not say what to practice. The research digest sorts every miss into four types: knowledge gap, procedure, careless and concept. Each type calls for a different fix:
| Type | What happened | Example | What to drill |
|---|---|---|---|
| Knowledge gap | You had never learned the pattern or trick. | You had never seen two pointers walk in from both ends of a sorted list. | The pattern's lesson, then its problems in a row. |
| Procedure | You knew the approach and fumbled the code. | You planned a running maximum, then could not make the loop update best correctly in time. | Re-solve missed problems from a blank editor until each takes under 15 minutes. |
| Careless | A slip: an off-by-one, a typo, a misread constraint. | range(len(nums) - 1) stopped one position early, so the last number was never checked. | Trace one example and the empty input by hand before every submit. |
| Concept | Your model of the cost or the data structure was wrong. | You assumed a set keeps its items in the order you added them. | Revisit Big O and how the structure works inside; state the cost before writing code. |
The most common type decides next week's drilling. Ten careless misses call for a habit (trace by hand before you submit), not more lessons. Ten knowledge gaps call for lessons, not more grinding.
Once you have run your code on a problem, or opened its solution, the page shows a Log a miss button. You pick the type and write a short note. The miss lands in your journal on the Progress page, and the problem stays in the Practice queue until you solve it again.
Your solution to a practice problem passed the small tests but ran out of time on the large one. You had written its cost as O(n). Inside the loop it runs if x in seen_list:, because you believed in takes one step on any collection. In fact in on a list checks the items one by one, so the real cost is O(n2). Which type of miss is this?
Choose one answer, then check.
Finding the most common type is a walk with a notebook. The Progress page does it over your last 15 entries. Here is the counting half, on a journal of five entries. The notebook is a dict (short for dictionary), a table of keys and values. counts["careless"] reads the value stored under the key "careless", and counts["careless"] += 1 adds one to it. Before you step through, guess the final count for "careless".
journal = ["careless", "procedure", "careless", "knowledge", "careless"]counts = {"knowledge": 0, "procedure": 0, "careless": 0, "concept": 0}for miss in journal:counts[miss] += 1print(counts)
(nothing printed yet)To finish the job, walk the four types and keep the one with the biggest count. That is the running maximum from the previous lesson, with two changes. The notebook best holds a type, not a count, and its count is read through it as counts[best]. And on a tie, the type that came first stays. Put the lines in order.
Put the lines in order to build dominant_miss(counts, types). counts is a tally like the one the trace printed, one count per miss type. types lists the four types in a fixed order, ["knowledge", "procedure", "careless", "concept"]. The function returns the type with the biggest count. On a tie it returns the tied type that comes first in types (the Progress page uses the same rule). Indentation is already part of each line. Two of the lines do not belong.
Add lines from the list below, in order.
def dominant_miss(counts, types):best = 0best = types[0]best = kindif counts[kind] > counts[best]:if counts[kind] >= counts[best]:return bestfor kind in types:
Mock rounds and the weeks ahead
How do you know when you are ready? Not from one good evening, but from a trend across mock rounds. A mock round is a practice interview under real conditions: an unseen problem (one you have never solved), a clock, no Run button, and you narrating out loud the whole time. Three points from the research digest:
- About five mocks, on average, before average scores cross the passing threshold (platform data). Early mocks that go badly are what the average looks like, not a verdict.
- Only about 25% of candidates were consistent across interviews (platform data). One great round and one awful round are both weak evidence.
- So judge readiness on the trend across your last five unseen-problem mocks, never on a single one. Start full mock conditions after about 50 to 60 problems.
The Mock round tab on the Practice page runs four formats, including Meta style (two mediums in 40 minutes) and Google style (one medium in 45). There is no Run button: your code runs once, when you submit, so you trace it by hand first. Then you score yourself from 1 (would sink the round) to 4 (strong) on the four scores from the first lesson: communication, problem solving, technical competency and testing. A round counts as passed when every problem passed and your scores average 3 or more; the last five show on the Progress and Plan pages.
Now the plan. The research digest flags a weak coding start: you cannot solve unseen easy problems in 30 minutes, or you have not practiced data structures and algorithms in 3 or more years. That start calls for an extended plan of 16 to 20 weeks instead of the usual 12, opening with a 2 to 3 week fundamentals ramp and including 10 to 14 coding mocks. If loops have felt slippery lately, this is your plan. The Plan page maps it onto this course over 18 weeks:
| Weeks | Focus | Modules | Practice |
|---|---|---|---|
| 1 to 3 | Fundamentals ramp: Python, costs, lists and hash maps | 0 to 3 | Every lesson's exercises and problems; no timing yet |
| 4 to 8 | One pattern at a time | 4 to 8 | 6 to 8 problems a week, 3 to 5 in a row per pattern; re-solves every session |
| 9 to 12 | The remaining patterns, then mixing | 9 to 13 | Mixed sets twice a week; first mock rounds, once a week |
| 13 to 16 | Interview mode | 14 | Mock rounds become the spine, one or two a week |
| 17 to 18 | Calibration and the readiness gate | none | Two or more mocks with a person; lower-stakes loops first |
Count the mocks in the last column and you reach the research's 10 to 14: 4 in weeks 9 to 12, 4 to 8 in weeks 13 to 16, and at least 2 in weeks 17 and 18.
A week has a fixed shape, so practice survives a busy job:
| When | How long | What |
|---|---|---|
| Four weekday sessions | 45 to 60 minutes each | Due re-solves first; then a lesson or new problems in weeks 1 to 8, mixed sets and mocks after that |
| One weekend block | 3 to 4 hours | A checkpoint, a timed set or a full mock round |
| One full day | Off | Rest |
The week in the first trace has this shape: four weekday sessions (Monday, Tuesday, Thursday and Friday), a 200-minute block on Saturday, and Sunday off. That is six days; Wednesday, the seventh, has nothing planned.
Track sessions completed, not problems solved: that is the count the trace makes. In platform data, the number of problems a candidate had solved was only weakly linked to how they ranked in interviews (a correlation of 0.27, where 1 is a perfect match and 0 no link). The sessions you keep are the part you control. The full plan, with a week 1 diagnostic and checklists to tick, is on the Plan page.
The whole routine, in one breath: predict before you run; write from memory; cap the struggle; re-solve on the ladder; block, then mix; log every miss by type; and read your readiness from your last five mocks.
A friend preparing for the same interviews tells you her method: every evening she reads three new solutions on a problem site until each one makes sense, and she never goes back to old ones. In a few plain sentences, say what you would change and why, as you would say it to her.
Saved in this browser as you type.