1706. Where Will the Ball Fall - LeetCode
class Solution:
def findBall(self, grid: list[list[int]]) -> list[int]:
N = len(grid[0])
def drop(pos: int) -> int:
for row in grid:
adj = pos + row[pos]
if not 0 <= adj < N:
return -1
if row[pos] != row[adj]:
return -1
pos = adj
return pos
return [drop(x) for x in range(N)]