Push-Up Connect Winner
MediumSimulation ยท Jane Street
Replay a connect game on a board with rows rows and cols columns. Players 1 and 2 alternate, player 1 first; moves[i] is the column chosen on move i + 1. The disc enters at the bottom and pushes the discs already in that column up one row; if the column was full, its top disc is removed.
After each move, look for k consecutive discs of one player in a row, column or diagonal. Return [m, w] for the first move m (1-based) after which a line exists, where w is the player who has one, or 0 if both do. If there is none, return [-1, 0].
Example 1
- Input:
- rows = 4, cols = 4, k = 3, moves = [0, 1, 0, 1, 0]
- Output:
- [5, 1]
- Explanation
- Player 1's three pushes into column 0 leave three of their discs stacked there after move 5.
Example 2
- Input:
- rows = 3, cols = 3, k = 3, moves = [0, 2, 2, 0, 1, 0, 2, 1]
- Output:
- [8, 1]
- Explanation
- Player 2's push into column 1 lifts player 1's disc there, completing a diagonal for player 1.
Example 3
- Input:
- rows = 2, cols = 3, k = 3, moves = [1, 1, 0, 0, 2, 2]
- Output:
- [6, 0]
Constraints
1 <= rows, cols <= 502 <= k <= max(rows, cols)0 <= moves.length <= 20000 <= moves[i] < cols