Glean·Software Engineer·Technical Phone Screen
- Implement the core move logic for a 2048 board. Given an n x n grid, write a method that slides and merges tiles in a given direction (up, down, left, right) according to standard 2048 rules.
- Follow-up: implement an isGameOver() check that returns true when no legal move remains, without necessarily simulating all four full moves.
- How would you signal to the caller that the board actually changed after a move, so the game knows when to spawn a new tile?
- How would you unit test the movement logic? What invariants always hold across any valid move?
“I started by trying to write separate logic for all four directions and immediately saw how messy that gets.”