Tap here to switch tabs
Problem
Submissions

Problem: The Maze

med
30 min
Try to solve the The Maze problem.

Statement

You are given an m×nm \times n maze, where 00 represents an empty cell, and 11 represents a wall.

A ball starts at position start = [start_row, start_col], and you want to determine whether it can stop exactly at position destination = [destination_row, destination_col].

The ball can be rolled in one of the four cardinal directions: up, down, left, or right. Once the ball starts moving, it continues rolling through consecutive empty cells in that direction until it encounters a wall or the boundary of the maze. The ball then stops at the last empty cell before the obstacle.

Because the ball only stops when its movement is blocked, it cannot stop in the middle of an open corridor.

Return TRUE if the ball can eventually stop at destination. Otherwise, return FALSE.

Important: The ball may pass through the destination while rolling, but this does not count as reaching it. The destination is considered reached only if the ball can stop exactly on that cell.

Constraints:

  • m == maze.length

  • n == maze[i].length

  • 11 \leq m, n 100\leq 100

  • maze[i][j] is 00 or 11

  • start.length == 2

  • destination.length == 2

  • 00 \leq start_row, destination_row <m< m

  • 00 \leq start_col, destination_col <n< n

  • Both the ball and destination are located on empty cells, and they are not initially in the same position.

  • The maze contains at least 22 empty cells.

Unlock AI-Powered LearningUpgrade to smarter learning with instant explanations of Ask Agent, Personalized Interview Prep, Real-World Projects, 3 AI Mock Interviews per month, and Personalized Paths
Tap here to switch tabs
Problem
Submissions

Problem: The Maze

med
30 min
Try to solve the The Maze problem.

Statement

You are given an m×nm \times n maze, where 00 represents an empty cell, and 11 represents a wall.

A ball starts at position start = [start_row, start_col], and you want to determine whether it can stop exactly at position destination = [destination_row, destination_col].

The ball can be rolled in one of the four cardinal directions: up, down, left, or right. Once the ball starts moving, it continues rolling through consecutive empty cells in that direction until it encounters a wall or the boundary of the maze. The ball then stops at the last empty cell before the obstacle.

Because the ball only stops when its movement is blocked, it cannot stop in the middle of an open corridor.

Return TRUE if the ball can eventually stop at destination. Otherwise, return FALSE.

Important: The ball may pass through the destination while rolling, but this does not count as reaching it. The destination is considered reached only if the ball can stop exactly on that cell.

Constraints:

  • m == maze.length

  • n == maze[i].length

  • 11 \leq m, n 100\leq 100

  • maze[i][j] is 00 or 11

  • start.length == 2

  • destination.length == 2

  • 00 \leq start_row, destination_row <m< m

  • 00 \leq start_col, destination_col <n< n

  • Both the ball and destination are located on empty cells, and they are not initially in the same position.

  • The maze contains at least 22 empty cells.

Unlock AI-Powered LearningUpgrade to smarter learning with instant explanations of Ask Agent, Personalized Interview Prep, Real-World Projects, 3 AI Mock Interviews per month, and Personalized Paths