FastPrepApply a 2048 Board Move
Problems/Apply a 2048 Board Move

Apply a 2048 Board Move

Glean logoGlean● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report asks for all four movement directions on a fixed 4-by-4 2048 board. We chose the usual rule that a tile merges once, that no new tile appears, and a wrapper function that returns the board. Our version is about 90% the same as the reported question.

You are given a fixed 4 x 4 2048 board and one direction: "LEFT", "RIGHT", "UP", or "DOWN". Apply one move and return the resulting board.

For each row or column along the chosen direction:

  1. Slide its nonzero tiles toward the chosen edge, closing the gaps.
  2. Starting at that edge and moving away from it, merge adjacent equal tiles once per move.
  3. Slide the tiles toward that edge again to close any new gaps.

A tile created by a merge cannot merge again during the same move. Do not spawn a random tile.

Function

move2048(board: int[][], direction: String) → int[][]

Examples

Example 1

board = [[2,0,2,2],[4,4,4,4],[0,0,2,2],[2,2,2,0]]direction = "LEFT"return = [[4,2,0,0],[8,8,0,0],[4,0,0,0],[4,2,0,0]]
board
012302022144442002232220
→
return
012304200188002400034200
Moved or new

Each row compacts left and each original tile participates in at most one merge.

Example 2

board = [[2,0,0,2],[2,0,0,2],[4,0,0,4],[0,0,0,0]]direction = "UP"return = [[4,0,0,4],[4,0,0,4],[0,0,0,0],[0,0,0,0]]
board
012302002120022400430000
→
return
012304004140042000030000
Moved or new

The two columns are processed independently toward the top edge.

Constraints

  • board.length == 4 and every row has length 4.
  • Every cell is zero or a positive power of two no greater than 1073741824.
  • direction is one of LEFT, RIGHT, UP, or DOWN.
  • Every merged value fits signed 32-bit arithmetic.

More Glean Phone Screen questions

  • Validate a Chess Bishop, Rook, or Queen MovePHONE SCREEN · Seen Nov 2026
  • Document Indexer Scheduling MetricsPHONE SCREEN · Seen Oct 2026
  • Group Transitive Synonyms by Four-Token ContextPHONE SCREEN · Seen Aug 2026
  • Sort One Displaced ElementPHONE SCREEN · Seen Jul 2026

Similar questions at other companies

  • Spiral Order with ObstaclesTemu · PHONE SCREEN
  • Incremental Hard Attention with a KV CacheOpenAI · PHONE SCREEN · ONSITE INTERVIEW
  • Spiral Matrix TraversalByteDance · PHONE SCREEN
  • S-Shaped Matrix TraversalFox Corporation · PHONE SCREEN
  • Longest Consecutive Same-Color LineGoogle · PHONE SCREEN
  • Process Minesweeper Game OperationsAmperity · PHONE SCREEN
  • Diagonal TraverseHive · PHONE SCREEN
  • Game of Life on a Finite and an Infinite BoardCitadel · PHONE SCREEN
  • Build a Bird’s-Eye-View Height GridNVIDIA · PHONE SCREEN
  • Multi-Channel Valid ConvolutionTesla · PHONE SCREEN
See Glean hiring insights
Saved
class Solution {
    public int[][] move2048(int[][] board, String direction) {
        // Write your code here.
    }

}
Checking account…