← Glean Interview Insights

Glean·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Glean SWE interview that was essentially a full game implementation problem. Not a leetcode grind session, more of a design-your-way-through-it situation.

Questions Asked (1)

Q1

Implement the 2048 game. Follow-up: how do you detect when the game is over?

Algorithms & Data StructuresSystem Design
Author's notes

The core implementation took a while to get right because merging tiles in a direction sounds trivial until you're actually coding it and realize you need to handle the order of merges carefully so tiles don't double-merge in one move.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements (board size, win condition, input method) and then outline the core components: board representation, move logic for each direction, tile merging, and random tile generation. For the follow-up, explain that game over occurs when no empty cells exist and no adjacent tiles can be merged, and describe an efficient check that avoids scanning the entire board unnecessarily.

Pro tip: Mention that you can detect game over by checking for empty cells and adjacent equal tiles, and optimize by only checking around the last moved tile. This shows you think about performance and edge cases.

1. Clarify Requirements

Ask about board size (typically 4x4), win condition (2048 tile), input method (keyboard), and whether to implement UI or just logic. Confirm expectations for the follow-up question.

2. Design Data Structures

Represent the board as a 2D array or list of lists. Consider using a class to encapsulate board state and operations. Plan how to store tile values (integers, 0 for empty).

3. Implement Core Move Logic

For each direction, implement a function that slides and merges tiles. Use a helper to process a single row/column: remove zeros, merge adjacent equal tiles, pad with zeros. Ensure each tile merges only once per move.

4. Add Random Tile Generation

After each valid move, add a new tile (2 or 4) in a random empty cell. Ensure the move is valid (board changed) before adding a tile.

5. Detect Game Over

Check if any empty cells exist. If not, check for any adjacent equal tiles horizontally or vertically. If neither, game over. Optimize by only checking around the last moved tile if needed.

Key Points to Mention

  • Board representation as a 2D array with 0 for empty cells.
  • Move logic: compress (remove zeros), merge, compress again.
  • Ensure each tile merges only once per move (e.g., [2,2,2,2] -> [4,4] not [8]).
  • Random tile generation: 90% chance of 2, 10% of 4 (or as specified).
  • Game over condition: no empty cells and no adjacent equal tiles.
  • Optimization: only check around the last moved tile for game over detection.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.