Load/Store Arithmetic Interpreter
Updated
Problem statement
Execute a small language over integer memory and one integer accumulator. The accumulator starts at 0; memory starts with the given array. Execute instructions once each, in order, and return the final memory array.
LOAD i: replace the accumulator with the current value of memory celli.STORE i: replace memory celliwith the accumulator; leave the accumulator unchanged.ADD v: add the literal integervto the accumulator.SUB v: subtract the literal integervfrom the accumulator.MUL v: multiply the accumulator by the literal integerv.
Memory addresses are zero-based. A later LOAD observes any earlier STORE to that cell. Arithmetic changes only the accumulator; memory changes only on STORE. The final accumulator is not part of the returned result. There are no branches, jumps, or additional operations.
Function
runProgram(memory: int[], instructions: String[]) → int[]Examples
Example 1
memory = [4,1]instructions = ["LOAD 0","ADD 3","STORE 1","MUL 2"]return = [4,7]Only STORE changes memory; the final multiplication affects the accumulator only.
Example 2
memory = [9,-2]instructions = ["STORE 0","LOAD 1","SUB -3","STORE 1"]return = [0,1]The accumulator starts at zero. Subtracting a negative value adds its magnitude.
Example 3
memory = [2,5]instructions = []return = [2,5]No instructions execute, so the returned memory has its initial values.
Constraints
1 <= memory.length <= 1000and0 <= instructions.length <= 10000.- Every instruction is valid: one listed uppercase opcode, one ASCII space, then one decimal integer with no extra whitespace.
- LOAD and STORE addresses are in
[0, memory.length - 1]. - Initial memory values, arithmetic operands, and every intermediate accumulator value are in
[-2147483648, 2147483647]. - Numeric operands use ordinary decimal notation, with an optional minus sign and no leading zeros except zero itself.
More Jane Street interview questions
- Maximum-Scoring Consecutive Tree LevelsPHONE SCREEN · Seen Nov 2026
- Tree Selection and VisibilityPHONE SCREEN · Seen Nov 2026
- Instrument Stack Language JumpsPHONE SCREEN · Seen Oct 2026
- Run a Stack Language InterpreterPHONE SCREEN · Seen Oct 2026
- Positive-Integer Expression EvaluationPHONE SCREEN · Seen Oct 2026
- Code Editor FoldingONSITE INTERVIEW · Seen Oct 2026
- Exact-Sixty Dice Game ValueONSITE INTERVIEW · Seen Oct 2026
- Expected Value of Modified DiceONSITE INTERVIEW · Seen Oct 2026
- Spaceship Equipment LoadoutONSITE INTERVIEW · Seen Oct 2026
- Two-Tower Strategy GameONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Elevator Scheduling SimulationOpenAI · PHONE SCREENOpenAI interview questions
- Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
- Parking Garage AllocatorAmazon · PHONE SCREEN
- Variadic Function Library MatchesIBM · PHONE SCREENIBM interview questions
- Project and Filter Structured RecordsStripe · PHONE SCREENStripe interview questions
- Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
- Ordered IP FirewallDatabricks · PHONE SCREENDatabricks interview questions
- Add Signed Character ArraysByteDance · PHONE SCREENByteDance interview questions
- Is This Tic-Tac-Toe Board ReachableAdobe · PHONE SCREENAdobe interview questions
- Wordle Guess LoopRetool · PHONE SCREENRetool interview questions