Two participants, identified by the strings "B" and "R", take turns placing pieces on the upper half-plane of an integer grid. Columns may be any integer, and rows are numbered 0, 1, 2, ... upward from the bottom.
A turn is represented by a pair [player, column] and affects only that column:
0.0.Pieces never move sideways, and only the played column changes during a move.
After each move, a player wins if the board contains k consecutive occupied cells in one horizontal row or one vertical column, all belonging to that player. Diagonal runs do not count. Since one move can shift an entire column upward, a single move may create winning lines for both players at the same time.
Process the moves in the given order and stop at the first move at which at least one player wins. Return [m, winners], where m is the 1-based index of that move and winners is the alphabetically sorted list of all players with winning lines at that moment: ["B"], ["R"], or ["B", "R"].
If no player wins after all moves have been processed, return [-1, []].
Example 1:
Input: k = 3, moves = [["B", 4], ["R", 4], ["B", 4], ["B", 5], ["B", 6]]
Output: [5, ["B"]]
Explanation: On move 5, row 0 contains "B" in columns 4, 5, and 6, forming a run of 3.
k = 3 moves = [["B",4], ["R", 4], ["B", 4], ["B", 5], ["B", 6]]
[5,["B"]]
Input: k = 3, and 5 moves. Each move is [player, column].
Example 2:
Input: k = 4, moves = [["R", 7], ["B", 7], ["R", 8], ["B", 8], ["R", 9], ["B", 9], ["R", 10], ["B", 10]]
Output: [8, ["B", "R"]]
Explanation: After move 8, row 0 contains "B" in columns 7 through 10, while row 1 contains "R" in those same columns, so both players complete a run of 4.
Example 3:
Input: k = 3, moves = [["R", -3], ["B", -3], ["R", -3], ["B", -3], ["R", -3]]
Output: [-1, []]
Explanation: All pieces are placed in column -3; from bottom to top the column contains ["R", "B", "R", "B", "R"], so no run of length 3 exists.
Constraints:
player is always "B" or "R"k = 3 moves = [["B",4], ["R", 4], ["B", 4], ["B", 5], ["B", 6]]
[5,["B"]]
Input: k = 3, and 5 moves. Each move is [player, column].