Google | Phone |
Anonymous User
3306

Position: L3
Location: India

Given a binary matrix, with 1 representing clear path and 0 representing wall. We can move in four directions(up, left, right, down). Find min number to steps to reach (n-1,n-1) from (0,0).

This was pretty standard question. I coded this up in no time.

Follow up 1: What if we can turn 1 wall to clear path ?

I was able to answer this by maintaining 2 distance vectors. One from origin to a certain point, another from a certain point to destination. The answer can be calculated by using these two distance vectors.

Follow up 2: What if we can turn n walls into clear paths ?
I wasn't able to come up with a solution for this. Any help in comments is really appreciated.

The interviewer was really supportive. He was really sweet and not for a moment made think I am a dumbass, which clearly I am :p
Thanks

Comments (4)