Design the move-processing logic for a generalized Tic-Tac-Toe game.
There are k players and an n x n board. Players take turns placing their own mark on an empty cell. Player numbers are 1 through k.
A player wins as soon as they have at least 3 consecutive marks in a straight line. The line may be horizontal, vertical, diagonal, or anti-diagonal. This winning length is always 3, even when n is larger than 3.
Given the move list, return the game status after each move:
"Game Over"if the move is attempted after a winner already exists."Player X won"if playerXwins on that move."Draw"if the board becomes full and nobody has won."In Progress"otherwise.
All moves in the input are within board bounds. If a move targets an already occupied cell before the game is over, leave the board unchanged and return "Invalid Move" for that move.
k = 2 n = 3 moves = [[1,0,0],[2,1,0],[1,0,1],[2,1,1],[1,0,2]] return = ["In Progress","In Progress","In Progress","In Progress","Player 1 won"]
Player 1 completes three consecutive marks across the top row.
k = 3 n = 4 moves = [[1,0,0],[2,0,1],[3,3,3],[1,1,1],[2,1,0],[3,2,1],[1,2,2]] return = ["In Progress","In Progress","In Progress","In Progress","In Progress","In Progress","Player 1 won"]
Player 1 completes the diagonal segment (0,0), (1,1), (2,2).
1 <= k <= 103 <= n <= 10^31 <= moves.length <= min(n^2 + 5, 10^5)- Each move is encoded as
[player, row, col], where1 <= player <= kand0 <= row, col < n.
- Consolidate On-Call RotationsOA · Seen Jun 2026
- Detonate Bombs with Chain ReactionsONSITE INTERVIEW · Seen May 2026
- Evaluate a Nested Math ExpressionONSITE INTERVIEW · Seen May 2026
- Longest Dictionary TokenizationPHONE SCREEN · Seen May 2026
- Minimum Cars for Rental RequestsONSITE INTERVIEW · Seen Apr 2026
- Shortest Path with Mandatory WaypointONSITE INTERVIEW · Seen Apr 2026
- Count Divisible Coin SelectionsOA · Seen Dec 2025
- Minimum Town Sum DifferenceOA · Seen Dec 2025
public String[] getGameStatus(int k, int n, int[][] moves) {
// write your code here
}