← Glean Interview Insights

Glean·Frontend Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Interviewed for a frontend role at Glean and got hit with a coding problem straight out of a game jam. The 2048 tilt mechanic sounds like a fun warmup until you're actually trying to handle merges and edge cases under pressure.

Questions Asked (1)

Q1

Implement the tile-sliding and merging logic from 2048. Given a 4x4 board, tiles should slide in a given direction (up, down, left, right), and adjacent tiles with equal values merge into one tile of double the value. Each tile can only merge once per move. Handle all four directions.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

I started with just left-slide since that felt easiest to reason about, got that working, then tried to rotate the board to reuse the same logic for other directions.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by explaining that you'll handle each direction by transforming the board so that sliding always occurs to the left, then applying a single slide-and-merge function, and finally reversing the transformation. Emphasize that the key is to process each row independently, merging adjacent equal tiles while ensuring each tile merges only once per move. Finally, discuss how to apply this to all four directions efficiently.

Pro tip: Mention that you can avoid duplicating logic for each direction by using board transformations (reverse rows, transpose) and that this approach reduces bugs and makes the code more maintainable. Also, note that you should handle the merge by iterating from the direction of movement to avoid double merges.

1. Clarify requirements and edge cases

Confirm the rules: tiles slide as far as possible, merges happen only between two tiles of equal value, and each tile can merge only once per move. Discuss edge cases like multiple merges in a row (e.g., [2,2,2,2] -> [4,4]) and no movement.

2. Design a helper for one direction

Implement a function that slides and merges a single row to the left. This function will iterate through the row, combining adjacent equal tiles and shifting non-zero tiles to the left.

3. Generalize to all directions

Use board transformations: for left, apply helper directly; for right, reverse each row, apply helper, then reverse back; for up, transpose the board, apply left helper, then transpose back; for down, transpose, reverse rows, apply helper, reverse rows, transpose back.

4. Implement and test

Write the code, ensuring that the board is updated correctly and that merges are handled without double merging. Test with various cases including no movement, single merge, multiple merges, and full board.

5. Analyze complexity and trade-offs

Discuss time complexity (O(n^2) for 4x4 board, effectively constant) and space complexity (O(1) if in-place, or O(n) for temporary arrays). Mention trade-offs between code clarity and performance.

Key Points to Mention

  • Use a single slide-and-merge function for one direction and transform the board for other directions to avoid code duplication.
  • When merging, iterate from the direction of movement (e.g., from left to right for left slide) to ensure each tile merges only once.
  • Handle zeros by compacting non-zero tiles before merging.
  • Consider in-place operations to minimize space, but temporary arrays can simplify logic.
  • Test with edge cases: [2,2,2,2] -> [4,4], [2,2,4] -> [4,4], [4,4,2,2] -> [8,4], and no movement.
  • Discuss how this logic integrates with the rest of the game (e.g., spawning new tiles, checking game over).

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