Code RoomTrace parcel deflectors
EasyPrep Room Coding #4824

Trace parcel deflectors

CodingAlgorithms & data structuresEntry–Mid~16 min

A parcel sorter routes packages over a grid of fixed deflectors, one deflector per cell. A cell holds '>' to push a parcel one cell right, '<' one cell left, '^' one cell up, 'v' one cell down, or 'O' for a chute that drops the parcel out of the machine. A parcel is placed on the cell at start_row and start_col, then follows whatever deflector it lands on. Return how many cells the parcel rests on, counting the one it starts on. The run ends at a chute, which counts, or when a deflector pushes the parcel off the belt, which does not. Return -1 when the parcel reaches a cell it has already rested on, since it then circles forever. Return 0 when the belt has no cells, or when the start is off the belt. Every row has the same width.

Implement
sorter_path_length(belt: list[list[str]], start_row: int, start_col: int) → int
Examples
in[[[">",">","O"]],0,0]out3
in[[[">","<"]],0,0]out-1
in[[["^","O"]],0,0]out1
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 16 min
InputExpectedGot
[[[">",">","O"]],0,0]3not run yetsample
[[[">","<"]],0,0]-1not run yetsample
[[["^","O"]],0,0]1not run yetsample