FastPrep2048 Simulation and Board Codec
Problems/2048 Simulation and Board Codec

2048 Simulation and Board Codec

Citadel logoCitadel● MediumINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Citadel intern onsite interview. The report asks for a 2048 simulation and for turning a board into one long long number and back. It leaves out the exact board, the merge and spawn rules, the bit layout, the function interface, the limits, and the examples. Our version uses a 4-by-4 board of exponents, with a fixed answer for every move. The packed signed values are written as text. It is about 75% the same as the reported question.

Process independent operations on a 4-by-4 2048 board. A board is a row-major array of 16 exponents. Exponent 0 means an empty cell; exponent e greater than zero means tile value 2^e.

  • ["ENCODE",e0,...,e15]: pack the board into 64 bits. Cell i occupies bits 4i through 4i+3, so cell 0 is the least significant nibble. Return one signed 64-bit decimal string.
  • ["DECODE",packed]: interpret the signed decimal string as a 64-bit two's-complement pattern and return its 16 exponent strings.
  • ["MOVE",direction,e0,...,e15]: move tiles left, right, up, or down using direction L, R, U, or D. Return the resulting 16 exponent strings.

For a move, slide nonempty tiles toward the chosen edge. In edge-first order, merge each adjacent equal pair once into a tile with exponent one larger. A tile formed by a merge cannot merge again during that move. Fill remaining cells with zeros. No new random tiles spawn. For example, moving exponent row [1,1,1,1] left gives [2,2,0,0], not [3,0,0,0].

Return one string array per operation, in input order. Each operation contains its own board or packed value and does not change another operation. Packed integers are decimal text so all 64 bits remain exact in every language.

Function

board2048Operations(operations: String[][]) → String[][]

Examples

Example 1

operations = [["MOVE","L","1","1","1","1","0","0","0","0","0","0","0","0","0","0","0","0"],["ENCODE","2","2","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],["DECODE","34"]]return = [["2","2","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],["34"],["2","2","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]]

The four equal tiles in the first row merge into two exponent-2 tiles. Encoding places 2 in the lowest nibble and 2 in the next nibble, giving 2 + 2 * 16 = 34. Decoding 34 recovers the same board.

Example 2

operations = [["ENCODE","15","15","15","15","15","15","15","15","15","15","15","15","15","15","15","15"],["DECODE","-9223372036854775808"]]return = [["-1"],["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","8"]]

Sixteen exponent-15 cells fill every bit with one, whose signed 64-bit value is -1. The minimum signed value has only bit 63 set, so decoding it gives exponent 8 in cell 15 and zeros elsewhere.

Constraints

  • 0 <= operations.length <= 2000.
  • Each operation has between 2 and 18 string fields.
  • ENCODE has exactly 16 exponents, each from 0 through 15.
  • DECODE has one signed integer from -9223372036854775808 through 9223372036854775807.
  • MOVE has one direction L, R, U, or D and exactly 16 exponents, each from 0 through 14.
  • All integer fields use canonical base-10 text: no plus sign or leading zeros, and zero is written as 0.

More Citadel Onsite Interview questions

  • Maximize Workday EarningsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Minimum Changes for Palindromic BlocksOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Removal PoolONSITE INTERVIEW · Seen Sep 2026
  • Centered K-by-K Submatrix SumsONSITE INTERVIEW · Seen Aug 2026
  • Search Suggestions with a Prefix TreeONSITE INTERVIEW · Seen Aug 2026
  • Traverse Interior Matrix Cells in Row-Major OrderONSITE INTERVIEW · Seen Aug 2026
  • Time-Based Key-Value StorePHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2026
  • Cancellable Priority Task QueueONSITE INTERVIEW · Seen Jan 2026
  • Dynamic Weighted SamplingONSITE INTERVIEW · Seen Jan 2026
  • Exchange Connection AlertsONSITE INTERVIEW · Seen Jan 2026

Similar questions at other companies

  • Game of Life: In-Place Next GenerationGoogle · ONSITE INTERVIEWGoogle interview questions
  • BitFont - Maximum Non-Overlapping KerningStripe · ONSITE INTERVIEWStripe interview questions
  • Hybrid Run-Length and Bit-Packing EncoderDatabricks · ONSITE INTERVIEWDatabricks interview questions
  • Repeated Mirror XORMathWorks · OAMathWorks interview questions
  • Out-of-Order TLV File ReassemblyApplied Intuition · PHONE SCREENApplied Intuition interview questions
  • Customer Bootstrap APIDoorDash · PHONE SCREEN · ONSITE INTERVIEWDoorDash interview questions
  • Propagating Fraud DetectorAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions
  • Deep Copy a Random-Pointer ListAmazon · ONSITE INTERVIEW
  • Digit-Coded Card ValidationCapital One · ONSITE INTERVIEWCapital One interview questions
  • Instant-Runoff Voting WinnerWise · ONSITE INTERVIEW

Interview reports that mention this question

  • Citadel SWE Intern First-Round Questions: 20 Experiences

Citadel interview experiences

  • Citadel Securities Quant Researcher Intern Loop: 1 Experience
  • Citadel Securities Research Engineer Interview: 1 Experience
  • Citadel Securities SWE Intern First Round: 2 Experiences
  • Citadel Securities Experienced SWE Interviews: 1 Experience
  • Citadel SWE Intern Later Rounds and Superday: 13 Experiences
All Citadel interview questionsSee Citadel hiring insights
Saved
class Solution {
    public String[][] board2048Operations(String[][] operations) {
        // Write your code here.
    }
}
Checking account…