Gantry crane minimum motions

Write codeMedium25 min

Your task

A gantry crane works a rectangular container bay drawn as a grid of single character cells. '.' is clear deck, '#' is a stack the crane cannot cross, 'S' is where the crane is parked and 'T' is the cell it has to reach. One motion runs the crane in a straight line up, down, left or right across any number of clear cells, and it may stop anywhere along that line, but it can never pass through or over a stack. Travelling ten clear cells in one straight run therefore costs the same single motion as travelling one. Return the fewest motions that bring the crane from S to T, or -1 when T cannot be reached. Every row has the same length, and S and T each appear exactly once. Both count as clear deck.

Examples

gantry_move_count(bay: list[list[str]]) -> int
Example 1
Inputgantry_move_count([["S", ".", "."], ["#", "#", "."], [".", ".", "T"]])
Output2
Example 2
Inputgantry_move_count([["S", "#", "T"]])
Output-1
Example 3
Inputgantry_move_count([["S", ".", ".", "."], ["#", "#", "#", "."], ["T", ".", ".", "."]])
Output3