0

For leetcode problem https://leetcode.com/problems/walls-and-gates/solution/

The BFS solution has

.......
private static final List<int[]> DIRECTIONS = Arrays.asList(
        new int[] { 1,  0},
        new int[] {-1,  0},
        new int[] { 0,  1},
        new int[] { 0, -1}
);
.....

This is to take turn right while traversing the matrix. Does anyone know how to derive these vectors without memorizing them?

My understanding is you do a cross product with (x,y,0) X (0,0,1) which gives R = yX -xY + 0Z. I think you take a partial derivative here but I'm unsure of the math proof which gives the directions.

Please explain mathematically how to get vectors {1,0} , {-1, 0}, {0,1} , {0,-1}

My understanding is you do a cross product with (x,y,0) X (0,0,1) which gives R = yX -xY + 0Z. I think you take a partial derivative here but I'm unsure of the math proof which gives the directions.

0 Answers0