Grokking Microsoft Coding Interview
Ask Author
Back to course home

0% completed

Vote For New Content
can someone please explain what does this do and why are we doing this? Queue ne...

Manthan

Dec 13, 2022

can someone please explain what does this do and why are we doing this? Queue neighbors = new LinkedList(); neighbors.add(new int[] { x, y }); while (!neighbors.isEmpty()) { int row = neighbors.peek()[0]; int col = neighbors.peek()[1]; neighbors.remove();

0

0

Comments
Comments
Design Gurus
Design Gurus3 years ago

This is the breadth first search (BFS) algorithm.

We are at node (x, y) and we want to traverse all the connected cells in BFS way.

We take one cell at a time, remove it from the LinkedList, mark it visited and insert all of its neighbours to the list.

Keep repeating...

On this page