Jane Coding Interview Question: Two-Player Grid Move Function on an Infinite Board

21 Views
No Comments

Simulate a game on a 2D grid that is infinite to the left, right, and top, but bounded at the bottom.

There are two players: Red, represented by R, and Blue, represented by B.

Keep track of the board state and implement a move function.

The move function takes an x position and places a piece at the bottom of that x-column, shifting everything above it upward.

This problem is a board simulation task for a two-player game on an infinite grid with a fixed bottom boundary. The key is to maintain column state efficiently: when a move is made in column x, place the new piece at the current lowest available position in that column and shift the pieces above it upward. A sparse representation such as a hash map keyed by column is typically the right approach, since the board is effectively unbounded and only occupied cells need to be tracked.

END
 0