2048 Move Simulator
Updated
Problem statement
Given a square 2048 grid and a string moves, apply the moves in order and return the final grid. L, R, U and D move tiles left, right, up and down.
Each move slides all nonzero tiles toward the side the move names and merges each adjacent pair of equal tiles once. Do not spawn new tiles.
Function
simulate2048(grid: int[][], moves: String) → int[][]Examples
Example 1
grid = [[2,0,2,2],[0,0,0,0],[0,0,0,0],[0,0,0,0]]moves = "L"return = [[4,2,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]Moved or new
In the top row, the first two equal tiles from the left merge, and the third tile slides in next to the result.
Constraints
2 <= grid.length <= 20and the grid is square.- Every entry is zero or a positive power of two.
movescontains onlyL,R,U, andD.- The sum of all starting tile values is at most
2147483647. Moves keep this sum the same because no tiles spawn.
More Benchling interview questions
- Minimum Genetic MutationOA · Seen Feb 2019
- Validate Nested JSON Against a SchemaONSITE INTERVIEW · Seen Dec 2025
- Bounded HTTP Retry FlowPHONE SCREEN · Seen Nov 2025
- Future-Aware Cache EvictionPHONE SCREEN · Seen Aug 2025
- Generate All Contiguous Protein ChainsPHONE SCREEN · Seen Jul 2024
- Degenerate DNA Substring SearchONSITE INTERVIEW · Seen Jun 2024
- Eight-Direction Keyboard Typing TimePHONE SCREEN · Seen Apr 2022
- Generate Proteins from Contiguous Named SequencesPHONE SCREEN · Seen Aug 2021
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Jul 2021
- Next Palindrome NumberPHONE SCREEN · Seen Jul 2021
Similar questions at other companies
- Maximum Diamond SumHudson River Trading · OAHudson River Trading interview questions
- Robot Navigation Around LasersRoblox · OARoblox interview questions
- Apply a Reversi MoveAmazon · OA
- Flip, Invert, and Smooth a Binary ImageAbridge · OAAbridge interview questions
- First Completed Mingo LineEpic · OAEpic interview questions
- Rotate a Square Matrix ClockwiseVisa · OAVisa interview questions
- Sort Concentric Matrix Borders ClockwiseByteDance · OAByteDance interview questions
- Sparse Valid Conv2D From ScratchNVIDIA · OANVIDIA interview questions
- Apply Matrix OperationsCapital One · OACapital One interview questions
- Rotate the Box and Drop the StonesZipRecruiter · OAZipRecruiter interview questions