Company: Thoughtspot
Difficulty: medium
Bob Navigates a Maze A warehouse robot named Rex has been tasked with retrieving every coin scattered across a storage grid before returning to its charging dock. Rex may only travel one step at a time, moving up, down, left, or right, and it must remain inside the grid on cells that are not obstructed. The grid is described by an n × m array. Each cell holds one of the following values: 0 is open 1 is blocked 2 is open with a gold coin Rex begins in the top-left cell (row, column) = (0, 0), and the charging dock sits at coordinates (x, y). Work out the fewest steps Rex needs to gather every coin in the grid and reach the dock afterward. If gathering all coins and reaching the dock is impossible, report -1 instead. Function Parameters maze[maze[0][0],...maze[n-1][m-1]] : a 2D array of integers x : an integer giving the row index of the charging dock y : an integer giving the column index of the charging dock Constraints 1 ≤ n, m ≤ 100 0 ≤ the number of coins ≤ 10 1 ≤ x 1 ≤ y Examples S