IBM interview question

Hackerrank Maze Question with follow ups.