This is a question that one of my friends saw during a phone screen for Google in Los Angeles. He was applying for a L4 position and he had about 4 YOE.
There is a robot at location (0, 0) of a 10x10 grid of tiles. Each tile can be one of 8 different colors: (0, 1, ... 7). There is a star at a known location (marked with the color -1) on the grid. You can program the robot by giving it a lookup table of color to direction. The robot will sense the color of the tile it is currently on, and move in the direction (up, down, left, or right) specified by the lookup table you provided. Output a lookup table that guides the robot to the star, if such a table is possible.
Small example grid:
[[(0), 1, 0, 0],
[3, 2, -1, 3],
[0, 0, 0, 2],
[0, 0, 0, 4]]Solution:
0: Right, 1: Down, 2: Left, 3: UpThere was no function signature given, just a blank IDE. I would love some input on how to solve this and what difficulty you all think it is. Thanks.