Problem 1559 · Medium

Detect Cycles in 2D Grid

Join neighbouring cells that hold the same letter in a union-find; a join between two cells already in one set closes a cycle.

Open the interactive visualisation