Apply One Swipe to a 2048 Puzzle Board and Score It

Last updated: November 29, 2026

Quick Overview

Given a 4 by 4 board of tile values (0 for empty) and a swipe direction, slide all tiles that way, merging equal neighbors once per move as in 2048. Return the new board, the points gained (sum of merged tile values), and whether the board changed.

Google
Coding & Algorithms
Frontend Engineer
Google
November 29, 2026
Frontend Engineer
Phone Screen
Coding & Algorithms
Medium

0

0

0 solved


Given a 4 by 4 board of tile values (0 for empty) and a swipe direction, slide all tiles that way, merging equal neighbors once per move as in 2048. Return the new board, the points gained (sum of merged tile values), and whether the board changed.

A Google phone screen problem that looks like a game but tests decomposition: write one row operation and reuse it for all directions via rotation or reversal. Interviewers watch for the merge-once rule, which most bugs violate.

What the Interviewer Expects
  • Implement compress-merge-compress for a single row moving left
  • Ensure a tile merges at most once per move ([2,2,2,2] becomes [4,4])
  • Reuse the row function for other directions by reversing or transposing
  • Report whether anything moved, since invalid moves should not spawn a tile
  • Keep the code short and testable
Key Topics to Cover
simulation
arrays
matrix transformation
game logic
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you spawn a new tile deterministically for testing?
  • How would you detect game over efficiently?
  • How would you write an AI that picks the best swipe with expectimax?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: board as 4 lists of 4 ints and direction in {'L','R','U','D'}. Rules: tiles slide as far as possible; two equal tiles that collide merge into their sum; a merged tile cannot merge again i...

High-Level Design

Write slide_left(row): drop zeros, scan left to right, merge a[i] == a[i+1] into one tile and skip past both, then pad with zeros. Directions map onto it: R reverses each row, U transposes, D tran...


Submit Your Answer
Markdown supported