A Timed Mock: One Coding Problem
A timed mock is a practice round that runs one coding problem under a fixed clock. The clock teaches pacing, not speed for its own sake.
Split the round into stages
A stage list keeps the clock visible. Coding gets the largest share, but testing keeps its own share.
plan = [("read and clarify", 5), ("plan and test cases", 10), ("code", 20), ("test and fix", 10)]
for stage, minutes in plan:
print(stage, minutes)
print("total:", sum(minutes for _, minutes in plan))Compare plans before coding
Comparing plans aloud shows the reasoning the interviewer scores. The hash map plan checks each number once.
print("brute force: check every pair")
print("hash map: check each number once against past numbers")
nums = [2, 7, 11, 15]
seen = {}
for num in nums:
seen[num] = True
print("seen:", sorted(seen))Work one problem end to end
The code stores each number with its position. For 7 it finds that 2 is already stored, so the pair is positions 0 and 1.
def two_sum(nums, target):
seen = {}
for i, num in enumerate(nums):
need = target - num
if need in seen:
return [seen[need], i]
seen[num] = i
return []
print(two_sum([2, 7, 11, 15], 9))Example
plan = [("read and clarify", 5), ("plan and test cases", 10), ("code", 20), ("test and fix", 10)]
print("mock plan minutes:", sum(minutes for _, minutes in plan))
def two_sum(nums, target):
seen = {}
for i, num in enumerate(nums):
need = target - num
if need in seen:
return [seen[need], i]
seen[num] = i
return []
print(two_sum([3, 8, 9, 5], 17))Key points
- Mock: a practice round that copies the real round, with the same stages and a clock.
- Pacing: giving each stage its own share of the minutes, instead of drifting.
- Use the first minutes to clarify the problem and to write small test cases.
- Use the last minutes to test the code on those cases and to fix what breaks.
- A hash map lookup turns a pair search into one pass over the list.
The plan adds to 45 minutes, so the mock stays inside one round. The solution then finds the pair 8 and 9, which adds to 17, at positions 1 and 2. The plan and the code together are the whole mock round.
Note
this lesson shows a timed walkthrough with a worked problem, not a real timer.
Try it Yourself
Edit the code, then press Run.
Running is simulated · Python Playground
Exercise
A timed mock round lasts 45 minutes. Which plan uses the round well?