Pergunta de entrevista da empresa Uber

A problem involving a maze in a 2D matrix.

Resposta da entrevista

Sigiloso

22 de dez. de 2017

A standard template for maze problems void search(int x, int y, T[][] maze, boolean[][] visited, List < Point > path) { if(x < 0 || y < 0 || maze.length <= x || maze[0].length <= y || visited[x][y]) { return; } //do something to maze[x][y] according to the question description //set (x,y) as visited visited[x][y] = true; //add (x, y) into current path path.add(new Point(x, y)); //search all explorable directions search(x + 1, y, maze, visited, path); search(x, y + 1, maze, visited, path); search(x - 1, y, maze, visited, path); search(x, y - 1, maze, visited, path); path.remove(path.size() - 1); visited[x][y] = false; //this is optional. depends on the question }