Tap here to switch tabs
Problem
Submissions

Problem: Detect Cycles in 2D Grid

Try to solve the Detect Cycles in 2D Grid problem.

Statement

Given a 2D grid of characters grid of dimensions m by n, determine if there is a cycle of identical values within the grid.

A cycle is defined as a sequence of cells such that:

  • The path begins and ends at the same cell.

  • The length of the sequence is at least 44.

  • All cells in the sequence contain the same character.

  • Each consecutive pair of cells in the sequence are adjacent horizontally or vertically.

  • The sequence does not revisit the cell visited immediately before the current cell.

Return true if grid contains at least one such cycle, and false otherwise.

Constraints:

  • m == grid.length

  • n == grid[i].length

  • 1≤1 \leq m, n ≤500\leq 500

  • grid consists only of lowercase English letters.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Detect Cycles in 2D Grid

Try to solve the Detect Cycles in 2D Grid problem.

Statement

Given a 2D grid of characters grid of dimensions m by n, determine if there is a cycle of identical values within the grid.

A cycle is defined as a sequence of cells such that:

  • The path begins and ends at the same cell.

  • The length of the sequence is at least 44.

  • All cells in the sequence contain the same character.

  • Each consecutive pair of cells in the sequence are adjacent horizontally or vertically.

  • The sequence does not revisit the cell visited immediately before the current cell.

Return true if grid contains at least one such cycle, and false otherwise.

Constraints:

  • m == grid.length

  • n == grid[i].length

  • 1≤1 \leq m, n ≤500\leq 500

  • grid consists only of lowercase English letters.