PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Glean

Implement 2048 tilt move

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's ability to implement array and matrix manipulation, deterministic state-transition logic, and rule-based merging behavior in a grid-based simulation.

  • hard
  • Glean
  • Coding & Algorithms
  • Software Engineer

Implement 2048 tilt move

Company: Glean

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Technical Screen

## Problem: Implement a 2048 “tilt” (move) operation You are given a **4×4** board for the game 2048. Each cell contains either **0** (empty) or a **power of two** (2, 4, 8, ...). When the player swipes in one of four directions (`up`, `down`, `left`, `right`), the board updates as follows: 1. **Shift:** All non-zero tiles move as far as possible in the swipe direction. 2. **Merge:** If two tiles with the **same value** collide during the move, they **merge into one tile** with value equal to the **sum** (i.e., doubled). 3. **Single-merge rule:** A tile can be merged **at most once per move**. 4. After merges, tiles continue shifting to fill gaps in the swipe direction. ### Task Implement a function that applies exactly **one** swipe (tilt) to the board. ### Function signature (language-agnostic) - Input: - `board`: 4×4 integer matrix - `dir`: one of `{up, down, left, right}` - Output: - The updated 4×4 board after the move ### Examples - Swipe left: - `[2, 0, 2, 4]` → `[4, 4, 0, 0]` - Swipe left (single-merge rule): - `[2, 2, 2, 0]` → `[4, 2, 0, 0]` (not `[8, 0, 0, 0]`) - Swipe left: - `[4, 4, 4, 4]` → `[8, 8, 0, 0]` ### Constraints / Notes - Board size is always 4×4. - Only implement the tilt/move logic (no random tile spawning, no scoring required unless you choose to return it as an extra). - Be careful with edge cases around multiple merges in a line and ensuring each tile merges at most once per move.

Quick Answer: This question evaluates a candidate's ability to implement array and matrix manipulation, deterministic state-transition logic, and rule-based merging behavior in a grid-based simulation.

Related Interview Questions

  • Return Top Department Suggestions - Glean (medium)
  • Implement Rate-Limited Wikipedia Crawler - Glean (medium)
  • Find Earliest Train Route - Glean (medium)
  • Search Words in a Character Grid - Glean (hard)
  • Find the Kth Largest in Two Sorted Arrays - Glean (medium)
Glean logo
Glean
Feb 11, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
18
0

Problem: Implement a 2048 “tilt” (move) operation

You are given a 4×4 board for the game 2048. Each cell contains either 0 (empty) or a power of two (2, 4, 8, ...). When the player swipes in one of four directions (up, down, left, right), the board updates as follows:

  1. Shift: All non-zero tiles move as far as possible in the swipe direction.
  2. Merge: If two tiles with the same value collide during the move, they merge into one tile with value equal to the sum (i.e., doubled).
  3. Single-merge rule: A tile can be merged at most once per move .
  4. After merges, tiles continue shifting to fill gaps in the swipe direction.

Task

Implement a function that applies exactly one swipe (tilt) to the board.

Function signature (language-agnostic)

  • Input:
    • board : 4×4 integer matrix
    • dir : one of {up, down, left, right}
  • Output:
    • The updated 4×4 board after the move

Examples

  • Swipe left:
    • [2, 0, 2, 4] → [4, 4, 0, 0]
  • Swipe left (single-merge rule):
    • [2, 2, 2, 0] → [4, 2, 0, 0] (not [8, 0, 0, 0] )
  • Swipe left:
    • [4, 4, 4, 4] → [8, 8, 0, 0]

Constraints / Notes

  • Board size is always 4×4.
  • Only implement the tilt/move logic (no random tile spawning, no scoring required unless you choose to return it as an extra).
  • Be careful with edge cases around multiple merges in a line and ensuring each tile merges at most once per move.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Glean•More Software Engineer•Glean Software Engineer•Glean Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.