FastPrepRun a Stack Language Interpreter
Problems/Run a Stack Language Interpreter

Run a Stack Language Interpreter

Jane Street logoJane Street● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Jane Street phone screen. The six instruction types are about 80% the same as the interview report. We chose string operands, how indices work, which direction truncation goes, what happens with an empty stack, and the return format.

Execute a simple stack program from instruction index 0 with an empty stack. Return the sequence of strings produced by PRINT, in execution order.

  • PUSH value pushes the entire string after the first space, including an empty string.
  • POP removes the top string; it does nothing on an empty stack.
  • PRINT appends the top string to the output without removing it; on an empty stack it appends "".
  • TRUNCATE k removes up to k characters from the right end of the top string. It leaves an empty string when k is at least its length, and does nothing on an empty stack.
  • JUMP target continues at the zero-based index target.
  • JUMP_IF_EMPTY target jumps when the stack is empty or its top string is empty; otherwise execution advances normally.

Every instruction other than a taken jump advances to the next index. Reaching index instructions.length ends execution. Inputs are valid and guaranteed to terminate; detecting infinite loops is unnecessary.

Function

runInterpreter(instructions: String[]) → String[]

Examples

Example 1

instructions = ["PUSH hello","PRINT","TRUNCATE 2","PRINT"]return = ["hello","hel"]

Printing preserves the top value. Truncation then removes its last two characters.

Example 2

instructions = ["PUSH ","JUMP_IF_EMPTY 4","PUSH skip","PRINT","PUSH ok","PRINT"]return = ["ok"]

The empty top value takes the jump directly to index 4, skipping the intervening instructions.

Example 3

instructions = ["POP","PRINT","PUSH abc","JUMP 5","PRINT"]return = [""]

Popping an empty stack is harmless. The first print emits an empty string, and the final jump exits the program.

Constraints

  • For this exercise, assume 0 <= instructions.length <= 1000 and at most 10000 executed instructions.
  • A pushed value has at most 50 printable ASCII characters, excluding line breaks. Its spaces are significant.
  • Non-PUSH operands are unsigned decimal integers. Truncation counts are at most 50; jump targets are in [0, instructions.length].
  • Opcodes are exactly the uppercase names above. Operand instructions have one separating space; PUSH represents an empty value. POP and PRINT have no operand.

More Jane Street Phone Screen questions

  • Maximum-Scoring Consecutive Tree LevelsPHONE SCREEN · Seen Nov 2026
  • Tree Selection and VisibilityPHONE SCREEN · Seen Nov 2026
  • Load/Store Arithmetic InterpreterPHONE SCREEN · Seen Oct 2026
  • Instrument Stack Language JumpsPHONE SCREEN · Seen Oct 2026
  • Positive-Integer Expression EvaluationPHONE SCREEN · Seen Oct 2026
  • Add Two Integers Given as StringsPHONE SCREEN · Seen Sep 2026
  • Angle Between Clock HandsPHONE SCREEN · Seen Jul 2026
  • Route Length From Two CyclistsPHONE SCREEN · Seen Jul 2026
  • Sort TradesPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
  • Painted Cube: Count and RollPHONE SCREEN · Seen Jul 2026

Similar questions at other companies

  • Adjacent Pair and Run RemovalWhatNot · PHONE SCREEN · ONSITE INTERVIEWWhatNot interview questions
  • Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
  • Multiline Text Editor with Cursor MovementDatologyAI · PHONE SCREEN
  • Trace Nested Object Destruction OrderArista Networks · PHONE SCREENArista Networks interview questions
  • Stack Language EvaluatorRetell AI · PHONE SCREENRetell AI interview questions
  • Text Document HistoryNotion · PHONE SCREEN · ONSITE INTERVIEWNotion interview questions
  • Text Editor, Part 2: Undo and RedoOpenAI · PHONE SCREENOpenAI interview questions
  • One-Dimensional Candy CrushBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Trace Events from Stable Whole-Stack StatesAnthropic · ONSITE INTERVIEWAnthropic interview questions
  • Most Frequent Call Path in Interleaved LogsRoblox · ONSITE INTERVIEWRoblox interview questions

Jane Street interview experiences

  • Jane Street TDO UK and Hong Kong: 22 Experiences (Part 10 of 10)
  • Jane Street TDOE US Final Round: 11 Experiences (Part 5 of 10)
  • Jane Street TDO Phone Math Round: 26 Experiences (Part 9 of 10)
  • Jane Street TDOE UK Phone Screen: 15 Experiences (Part 4 of 10)
  • Jane Street TDO Excel and VBA Test: 23 Experiences (Part 8 of 10)
  • Jane Street TDOE UK Coding Round: 15 Experiences (Part 3 of 10)
All Jane Street interview questionsSee Jane Street hiring insights
Saved
class Solution {
    public String[] runInterpreter(String[] instructions) {
        // Write your code here.
    }
}
Checking account…