Connect Four from the Last Move
Problem statement
A rectangular Connect Four board contains 0 for empty cells and 1 or 2 for player pieces. The piece at [row, col] is the move that was just placed by player.
Return whether that move belongs to a horizontal, vertical, or diagonal contiguous run of at least four player pieces. You only need to determine whether the supplied move completes a run; do not validate gravity or earlier game history.
Function
didPlayerConnectFour(board: int[][], row: int, col: int, player: int) → booleanExamples
Example 1
board = [[0,0,0,0],[1,1,1,1],[0,0,0,0]]row = 1col = 3player = 1return = trueThe supplied move completes a horizontal run of four.
Example 2
board = [[2,0,0,0],[0,2,0,0],[0,0,2,0],[0,0,0,2]]row = 2col = 2player = 2return = trueThe move lies on a four-piece diagonal.
Example 3
board = [[1,1,1,0]]row = 0col = 2player = 1return = falseThree contiguous pieces are not enough.
Constraints
1 <= board.length, board[i].length <= 200.- All rows have equal length and every cell is
0,1, or2. rowandcolidentify a valid cell andplayeris1or2.