FastPrepMerge a 2048 Row
Problems/Merge a 2048 Row

Merge a 2048 Row

Palantir logoPalantir● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Palantir phone screen. The interviewer asked for a function that shifts the 0's to the end, and a function that doubles matching pairs, such as 2 and 2 becoming 4.

The report gives the three examples below but no size or value limits. Here, each tile merges once per move, no random tile is added, and an empty row stays empty.

Our version is about 95% the same as the reported question.

Return the result of one left move on a single row of 2048 tiles.

  1. Move every nonzero tile left, keeping its relative order.
  2. Scan those tiles from left to right. If the next two tiles have the same value, replace them with one tile of twice that value. Each tile can take part in at most one merge during this move.
  3. Fill the remaining positions on the right with zeros. The returned row has the same length as the input.

For this exercise, assume the move adds no random tile. An empty row returns an empty row.

Function

mergeRow(row: int[]) → int[]

Examples

Example 1

row = [2,0,2,0]return = [4,0,0,0]

Removing zeros leaves [2,2]. These two tiles merge into 4, followed by three zeros.

Example 2

row = [2,2,4,4]return = [4,8,0,0]

The first two tiles merge into 4. The next two merge into 8. Neither new tile merges again during this move.

Example 3

row = [2,4,2,4]return = [2,4,2,4]

No adjacent nonzero tiles have the same value, so the row stays unchanged.

Constraints

  • 0 <= row.length <= 10^4.
  • 0 <= row[i] <= 2^20.
  • Each nonzero value is a power of two.

More Palantir interview questions

  • Query Words Within K PositionsPHONE SCREEN · Seen Nov 2026
  • Balanced Session ManagerPHONE SCREEN · Seen Oct 2026
  • Employees With Shared InterestsPHONE SCREEN · Seen Jul 2025
  • Encrypt Letters by First-Occurrence SubstitutionPHONE SCREEN · Seen Aug 2022
  • Encrypt Text by Columnar TranspositionPHONE SCREEN · Seen Aug 2022
  • Basic Item DiscountsOA · Seen Nov 2026
  • Optimize Discount Selection Under a Point BudgetOA · Seen Nov 2026
  • Stacked Item and Category DiscountsOA · Seen Nov 2026
  • Map and Accumulate Learning QueriesONSITE INTERVIEW · Seen Oct 2026
  • Relational Learning QueriesONSITE INTERVIEW · Seen Apr 2025

Similar questions at other companies

  • Candy Crush Grid Matching and GravityRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
  • Add Signed Character ArraysByteDance · PHONE SCREENByteDance interview questions
  • Nested List Iterator with RemoveAirbnb · PHONE SCREENAirbnb interview questions
  • DMA Stream DistributionEtched · PHONE SCREEN
  • Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Collect Branches for a Bird NestVisa · OAVisa interview questions
  • Alternate Positive and Negative ValuesTesla · ONSITE INTERVIEWTesla interview questions
  • Score Difference When Even Picks Reverse the ListMicrosoft · OAMicrosoft interview questions
  • Sum Two Piecewise-Constant Time SeriesGoogle · ONSITE INTERVIEWGoogle interview questions
  • Match OutcomesAdobe · OAAdobe interview questions

Interview reports that mention this question

  • Palantir FDSE OA and Interviews: 16 Experiences (Part 1 of 2)

Palantir interview experiences

  • Palantir FDSE Experienced-Hire Interviews: 5 Experiences
  • Palantir FDSE New Grad OA Questions: 6 Experiences (Part 2 of 2)
  • Palantir FDSE New Grad Interviews: 5 Experiences (Part 1 of 2)
  • Palantir FDSE Intern OA and Interviews: 3 Experiences
  • Palantir FDSE Karat and Learning: 7 Experiences (Part 2 of 2)
All Palantir interview questionsSee Palantir hiring insights
Saved
class Solution {
    public int[] mergeRow(int[] row) {
        return row;
    }
}
Checking account…