Sollicitatievraag bij X

first round interview

Antwoorden op sollicitatievragen

Anoniem

28 jan 2015

Dynamic programming

5

Anoniem

20 feb 2015

BFS is a good option here.

2

Anoniem

9 jun 2015

Recursion (row, column, currentPostition), this not the entire answer but you would use recursion to solve this move accordingly

Anoniem

3 apr 2016

int shortestPathLength(int[][] grid) { if (grid == null || grid.length == 0) { return 0; } int n = grid.length, m = grid[0].length; int[][] cache = new int[n][m]; if (grid[0][0] != 0) { return 0; } else { cache[0][0] = 1; } for (int i = 1; i < n; i++) { cache[i][0] = (grid[i][0] != 1 && cache[i - 1][0] != 0) ? cache[i - 1][0] + 1 : 0; } for (int j = 1; j < m; j++) { cache[0][j] = (grid[0][j] != 1 && cache[0][j - 1] != 0) ? cache[0][j - 1] + 1 : 0; } for (int i = 1; i < n; i++) { for (int j = 1; j < m; j++) { if (grid[i][j] != 1) { if (cache[i - 1][j] == 0 && cache[i][j - 1] == 0) { cache[i][j] = 0; } else if (cache[i - 1][j] == 0 || cache[i][j - 1] == 0) { cache[i][j] = cache[i - 1][j] + cache[i][j - 1] + 1; } else { cache[i][j] = Math.min(cache[i - 1][j], cache[i][j - 1]) + 1; } } } } printArrayI(cache); return cache[n - 1][m - 1]; }

Anoniem

9 dec 2014

I guess use A*?