A warehouse robot moves on a square floor of n × n tiles. Open tiles are 1, and tiles covered by shelves are 0. The robot starts on the top-left tile and must reach its charging dock on the bottom-right tile. It moves one tile at a time: D (down), L (left), R (right) or U (up). It never leaves the floor, never enters a shelf, and never steps on the same tile twice in one route.
Write findAllRoutes(grid), where grid is an array of n rows, each an array of n numbers. It returns every possible route as a string of move letters, such as "DDRR", sorted in alphabetical (string) order.
Rules:
A route ends as soon as it reaches the dock.
If the start or the dock is a shelf, there are no routes: return []. On a 1 × 1 open floor the robot is already home, so the answer is [""].
If grid is not a non-empty square array of arrays, or any cell is not 0 or 1, throw a TypeError.
Do not modify grid.
n is at most 8, and the tests only use floors with at most 10,000 routes. A fully open 5 × 5 floor already has 8,512.