Trains the technique from
LeetCode 1824Minimum Sideway JumpsThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
Three tracks numbered 1, 2 and 3 run side by side from point 0 to the last point of a chute. blocks[i] names the one track shut at point i, or is 0 when no track is shut there.
A trolley starts at point 0 on track 2 and rolls forward to the last point. It cannot roll onto a point where its own track is shut.
At any point the trolley may jump sideways to either of the other two tracks, so long as that track is not shut at that point. A jump from track 1 straight to track 3 counts as one jump. Rolling forward costs nothing.
Return the fewest jumps needed to reach the last point on any track. A way through always exists.
Example 1
Track 2 is shut at the middle point, so a single jump onto either other track carries the trolley through.
Example 2
Track 2 is shut at every point along the way, so one jump at the start onto another track is enough and nothing further is needed.
Example 3
Track 3 is shut at the first point so the trolley jumps to track 1. Track 1 is shut at the third point and track 2 is shut where the trolley stands, so the second jump has to go straight across from track 1 to track 3.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def min_side_jumps(blocks: list[int]) -> int:public int minSideJumps(int[] blocks)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.