Exam Rank 05
ExamM5
Last timed Python exam in the examshell before the final project.
Requires
Unlocks
Guide
Exam Rank 05 is the last exam of the core (milestone M5; placement Reported by students), in Python, taken alone through examshell on a campus machine with no internet. It has the fewest levels and the hardest exercises: grids, graphs, scheduling and encoding problems where you must design the algorithm and handle every edge case on the first try. Details below come from simulators and student notes (Reported by students); the official pool can differ by campus and version.
What you will learn
- Modelling a problem as a graph or a grid before coding
- BFS for shortest transformations, DFS and flood fill for connected regions
- Cycle detection in directed and undirected graphs
- Interval scheduling with sorting and greedy choices
- Run-length style encoding and decoding with exact round trips
- Generating matrices in non-trivial orders (spirals)
Before you start
- Previous nodes: Exam Rank 04 and the M5 projects (Agent Smith, The Answer Protocol, Inception).
- Register for an exam session on the intra.
- Be fluent in writing BFS with a queue and DFS with an explicit stack in plain Python.
- Train with a simulator that includes the Rank 05 pool.
Plan of attack
- Two weeks before: list the reported exercises:
compress_decompress,spiral_generator,graph_cycle_detector,schedule_meetings,island_matrix_counter,prism_detector,word_ladder. - Grids: write flood fill (
island_matrix_counter) and spiral traversal until you can do them in ten minutes, including empty and one-row grids. - Graphs: BFS for
word_ladder(shortest number of steps), cycle detection with colours for directed graphs and with a parent check for undirected ones. - Scheduling: sort intervals by start or end and reason about overlaps; know which ordering each question needs.
- Encoding: make
decompress(compress(x)) == xhold for empty strings, single characters and long runs. - One week before: a full mock exam with the real time limit.
- During the exam: sketch the algorithm, list the edge cases, write the code, test every case, then
grademe.
def count_islands(grid: list[list[int]]) -> int:
seen: set[tuple[int, int]] = set()
count = 0
for row in range(len(grid)):
for col in range(len(grid[row])):
if grid[row][col] == 1 and (row, col) not in seen:
count += 1
stack = [(row, col)]
while stack:
r, c = stack.pop()
if (r, c) in seen or not (0 <= r < len(grid)):
continue
if not (0 <= c < len(grid[r])) or grid[r][c] != 1:
continue
seen.add((r, c))
stack += [(r + 1, c), (r - 1, c), (r, c + 1), (r, c - 1)]
return count
Common pitfalls
- Index errors on ragged or empty grids.
- BFS without a visited set, which explodes on
word_ladder. - Confusing directed and undirected cycle detection.
- Off-by-one errors on interval boundaries (does a meeting ending at 10 conflict with one starting at 10?).
- Recursion depth errors on large grids: use an explicit stack.
- Using a forbidden built-in or an import.
How it is evaluated
- Fully automatic, with hidden tests including large and degenerate inputs.
- Reported format: three levels, one exercise per level, all levels needed to pass.
- A failure lets you retry the level.
- Reported duration: about three hours. No internet and no personal files.