Phone interview | Mountain View | L3 | Google
460

I wasnt sure how to solve this:

// Assume it's N^N board.

// 2 is start and end point, 1 is the road, and 0 is the wall. We can move to up, down, left, and right if the next node is 1.

// Find the shortest path that can go from start to end:

// public Path findPath(int[][] board, int[] start, int[] end) {

// }

// int[][] board = {

// {0,2,0,0,0,0},

// {0,1,1,0,0,0},

// {1,1,1,1,1,0},

// {1,0,0,0,1,0},

// {1,1,1,1,1,0},

// {0,0,2,0,0,0}};

// int[] start = {0,1};

// int[] end = {5,2};

Result/Output: [[0,1],[1,1],[2,1],[2,0],[3,0],[4,0],[4,1],[4,2],[5,2]]

Comments (3)