Robot minimum turns

Write codeHard40 minGoogle style

Your task

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.

Examples

min_direction_changes(grid: list[list[int]]) -> int
Example 1
Inputmin_direction_changes([[0, 0, 0]])
Output0