GleanCodingFree preview
2048 Board Tilt
Implement the 2048 tilt (swipe) operation on a fixed 4x4 board: tiles slide fully in the swiped direction and equal adjacent values merge. All four directions are required, candidates are expected to write and run their own tests, and a common follow-up asks how to detect game over.
SWE
grid
simulation
array
medium
Frequency
Medium
Last asked
2026-10-20
Stage
phone-screen
Problem
- Implement the tilt function of the 2048 game on a fixed 4x4 board.
- A swipe in one of four directions (up / down / left / right) slides every tile as far as possible in that direction and collapses the board.
- When two tiles with the same number meet during the slide, they merge.
- All four directions must be handled; a solution that only supports one direction is treated as incomplete.
- Write your own test cases and run them during the interview.
Pitfalls
- The logic is not hard, but there are many edge cases; candidates who handled only one direction (and described the other three verbally) were rejected.
- Writing four separate hand-coded direction loops is slow and error-prone under time pressure; candidates who struggled cite unfamiliarity with matrix manipulation.
- Testing is part of the bar: interviewers expect you to drive the code with your own cases, so leave time to run them.
- The round is often staged: the interviewer asks for one direction (left) first, with tests running, and only then for all four directions.
- Interviewers tend to prefer the transform approach (rotate or reverse and transpose the board, then reuse the left collapse). Handling the four directions by adjusting row and column indices directly can work, but it is harder to defend and was received less favorably.
- Project and background questions can share the same hour; candidates who let that discussion run long never reached the follow-up.
Follow-ups
How do you determine that the game is over?
How do you determine a win or a loss?
Preparation
- Implement the single-row collapse (slide + merge) for one direction, then derive the other three directions from it, all within 25 minutes.
- Write a small test set covering empty rows, full rows with no merges, and rows with several equal values in sequence, and run it before moving to the next direction.
- Implement a game-over check on top of your tilt function.
Was this article helpful?
Comments
Sign in to join the discussion
Loading...
