Save 25%Black Friday: 25% off all plans — use code BLACKFRIDAY2026 at checkout. Ends Monday, Dec 7.Claim the deal

Design and implement a Connect Four style game board that supports dropping colored pieces into columns. In this board game, pieces fall vertically under gravity and settle at the lowest available position in the chosen column.

Implement the ConnectFourBoard class:

  • ConnectFourBoard(int rows, int cols) Initializes a game board with the specified number of rows (height) and cols (width). All cells start empty, represented by the character '0'.

  • char[][] drop(char color, int col) Drops a piece of the specified color into column col. The piece falls to the lowest available row in that column. Returns an independent copy of the current board state as a 2D character array after the drop operation.

    • Empty cells are represented by '0'
    • Colored pieces are represented by their characters (e.g., 'R' for red, 'Y' for yellow, 'B' for blue)
    • If the column is already full, the board remains unchanged
Test Cases
Input
Output
Expected