Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
islandTraversal += "B"; // back why is this necessary?

Dhruba Jyoti Nath

Aug 4, 2022

islandTraversal += "B"; // back why is this necessary?

6

0

Comments
Comments
E
Eric C3 years ago

That makes sure that we keep note of when we backtrack in the DFS algorithm. Otherwise, we could have two distinct islands with the same string paths in some cases.

e.g. [{1, 1, 0}, {0, 1, 1}] and [{1, 1, 1}, {0, 1, 0}] would both have a path of "RDR" if we did not inc...

On this page