Menu

1559. Detect Cycles in 2D Grid
📰

1559. Detect Cycles in 2D Grid

DEV Community·MD ARIFUL HAQUE·6 months ago
#525KO7Ng
#leetcode#php#algorithms#programming#cell
Reading 0:00
15s threshold

1559. Detect Cycles in 2D Grid

Difficulty: Medium

Topics: Senior Staff , Array , Depth-First Search , Breadth-First Search , Union-Find , Matrix , Biweekly Contest 33

Given a 2D array of characters grid of size m x n , you need to find if there exists any cycle consisting of the same value in grid .

A cycle is a path of length 4 or more in the grid that starts and ends at the same cell. From a given cell, you can move to one of the cells adjacent to it - in one of the four directions (up, down, left, or right), if it has the same value of the current cell.

Also, you cannot move to the cell that you visited in your last move.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.