Google | Phone Screen | Random Walk
Anonymous User
1927

I had a Google phone screen last week with a Google software engineer. He was a team lead at Google from a few years. We went directly in the coding question after greeting each other. No questions about the resume or my background. The question was, given 2 points in a 2d array of all 0s, generate a random walk and return the grid.
Every time a random walk should be returned (the bigger the better, but not necessary). You can walk in the 4 directions up, down, left and right. While determining a solution, how would you make sure that a spiral path was not created, how would you make sure you always end up at the destination and not in either corners or way inside the path you'e making.

eg.
[
[0 0 0 0]
[0 0 0 0]
[0 0 0 0]
[0 0 0 0]
]

You can mark a position 1 when you have stepped over that position.
assume the start was (0, 0) and end was (3, 3).

The paths can be
[
[1 1 0 0]
[0 1 1 1]
[0 1 1 1]
[0 0 0 1]
]

The above path goes (0,0) - > (0,1) - > (1,1) - > (2,1) - > (2,2) - > (1,2) - > (1,3) - > (2,3) - > (3,3)

Every time a random walk should be returned.

I tried to play along these lines : https://www.geeksforgeeks.org/random-walk-implementation-python/
But I could not give a final solution for a 2D array.

Hope this helps someone.

Comments (7)