Code RoomGantry crane minimum motions
MediumPrep Room Coding #4902

Gantry crane minimum motions

CodingAlgorithms & data structuresMid–Senior~25 min

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.

Implement
gantry_move_count(bay: list[list[str]]) → int
Examples
in[[["S",".","."],["#","#","."],[".",".","T"]]]out2
in[[["S","#","T"]]]out-1
in[[["S",".",".","."],["#","#","#","."],["T",".",".","."]]]out3
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 25 min
InputExpectedGot
[[["S",".","."],["#","#","."],[".",".","T"]]]2not run yetsample
[[["S","#","T"]]]-1not run yetsample
[[["S",".",".","."],["#","#","#","."],["T",".",".","."]]]3not run yetsample