Search⌘ K
AI Features

Where Will the Ball Fall

Explore how to simulate the paths of balls falling through a 2D grid with diagonals that redirect them. Learn to identify when balls fall out of the box or get stuck by detecting patterns and boundary conditions. This lesson helps you implement logic for matrix traversal and understand directional movements within grids, enhancing your problem-solving skills for coding interviews.

Statement

You have nn balls and a 2D grid of size m×nm \times n representing a box. The box is open on the top and bottom sides. Each cell in the box has a diagonal that can redirect a ball to the right or the left. You must drop nn balls at each column’s top. The goal is to determine whether each ball will fall out of the bottom or become stuck in the box. Each cell in the grid has a value of 11 ...