Practice Where Will the Ball Fall
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Drop one ball from the top of each column of grid. A cell with 1 has a top-left to bottom-right board directing the ball right; -1 has the opposite slope directing it left. A ball gets stuck when directed into an outside wall or a V formed by opposing adjacent boards. Otherwise it continues down through the rows. Return each ball's exit column, or -1 if stuck, in starting-column order.
Source: Where Will the Ball Fall on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
grid = [[1,1,1,-1,-1],[1,1,1,-1,-1],[-1,-1,-1,1,1],[1,1,1,1,-1],[-1,-1,-1,-1,-1]]
[1,-1,-1,-1,-1]
# Example 2
grid = [[-1]]
[-1]
# Example 3
grid = [[1,1,1,1,1,1],[-1,-1,-1,-1,-1,-1],[1,1,1,1,1,1],[-1,-1,-1,-1,-1,-1]]
[0,1,2,3,4,-1]
Constraints
Related LeetCode Problems
Practice more problems similar to Where Will the Ball Fall.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.