Code Room
CodingHardcod-g250
Subject 0 1 bfsLevel Senior–Staff~40 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

A robot starts at the top-left (0,0) of a grid and must reach the bottom-right corner, moving up/down/left/right through open cells only (grid value 0; value 1 is a wall). Continuing straight is free, but each 90-degree turn costs one. The robot may choose any initial direction for free. Return the minimum number of turns, or -1 if the destination is unreachable or either corner is a wall. Constraints: 1 <= rows, cols <= 100.

Implement
min_direction_changes(grid: list[list[int]]) → int
Examples
in[[[0,0,0]]]out0
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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.