Skip to the guide

Design 2048

IntermediateCase study11 pages

The interviewer asks you to design 2048, the sliding-number puzzle Gabriele Cirulli released in 2014. Picture a tray of numbered wooden blocks on a table. You tilt the tray, every block slides to the low side, and two blocks with the same number that bump become one block with their sum. Then a friend drops one new block into a space. If you tilt and nothing moves, your friend drops nothing.

The closest other case study is snake and ladder, which also passes its randomness in. The merge has a trap that many first drafts fall into, and undo forces a real choice.

Below is a full 45-minute round on the LLD framework. You are the candidate. At each Guess before you read on, stop and answer first. The full runnable project, with its tests, is a download in Java, JavaScript and Python.

Run the full project

This design as a project you can run, with its tests and a demo. You only need Java 21, Node 24 or Python 3.13. The README says how to run it.

Step 1 · Clarify the requirements and cut the scope

Minutes 0–5 · How this step works

Interviewer: Design 2048.

You: How big is the board, and how many people play?

Interviewer: 4 by 4, and one person. The size may become a setting.

You: What appears after a move?

Interviewer: One new tile on a random free cell, a 2 nine times in ten and otherwise a 4. A game starts with two tiles. We also want a hard mode that places tiles differently, and more modes after that.

You: Can a tile that has just merged merge again in the same move?

Interviewer: No. A tile merges at most once per move.

You: What ends the game, and is undo part of this?

Interviewer: Reaching 2048 wins, and a full board with no merge left loses. Undo is in, for the last 100 moves, with no redo.

You: Then I'll build move and undo with the score. A move that changes nothing spawns no tile and isn't kept for undo. Screens, animation and playing on past 2048 are out. OK?

Interviewer: Good.