educative.io

Connecting all leaf nodes with a doubly linked list

How will we find neighboring grids of a given grid? Since only leaf nodes contain a list of locations, we can connect all leaf nodes with a doubly linked list. This way we can iterate forward or backward among the neighboring leaf nodes to find out our desired locations.

how do we order the data in such as way that we can iterate forward or backward to find the desired locations.

1 Like