Instrument Stack Language Jumps
Updated
Problem statement
Update a stack-language program by adding these three diagnostic instructions immediately before each original unconditional JUMP target instruction: PUSH jump@i, PRINT, POP, where i is that jump's original zero-based index.
Return the transformed instruction list. These diagnostic instructions print the original jump index and restore the original stack before the jump executes.
Rewrite the target of every original JUMP and JUMP_IF_EMPTY. A target naming an original instruction must point to the beginning of that instruction's transformed block, including its diagnostic prefix when it is an unconditional jump. The original end target instructions.length must become the transformed program length.
Add diagnostic instructions only for unconditional JUMP instructions from the original program. Keep every other instruction exactly as it was, except for updated conditional-jump targets. Do not add diagnostics for the instructions you insert, and do not run the program.
Function
instrumentJumps(instructions: String[]) → String[]Examples
Example 1
instructions = ["PUSH x","JUMP 3","PUSH skip","PRINT"]return = ["PUSH x","PUSH jump@1","PRINT","POP","JUMP 6","PUSH skip","PRINT"]The original index 3 moves to index 6 after the three diagnostics inserted before the jump at index 1.
Example 2
instructions = ["JUMP_IF_EMPTY 2","JUMP 3","JUMP 3"]return = ["JUMP_IF_EMPTY 5","PUSH jump@1","PRINT","POP","JUMP 9","PUSH jump@2","PRINT","POP","JUMP 9"]The conditional jump now targets index 5, the diagnostic entry for the original jump at index 2. Both unconditional jumps now target the new end index 9.
Example 3
instructions = ["PUSH JUMP 0","PRINT"]return = ["PUSH JUMP 0","PRINT"]Text inside a pushed value is data, so neither instruction is instrumented.
Constraints
- For this exercise, assume
0 <= instructions.length <= 1000. - Each original instruction is
PUSH value,POP,PRINT,TRUNCATE k,JUMP target, orJUMP_IF_EMPTY target. - A pushed value has at most
50printable ASCII characters excluding line breaks. Preserve its spaces;PUSHmay have an empty value. - Opcodes are uppercase. Operand instructions have one separating space. Numeric operands use unsigned decimal notation without leading zeros except
0. - Jump targets are valid original indices or the original end index. Backward and self-jumps are allowed because this function only transforms instructions.
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
- Run a Stack Language InterpreterPHONE 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
- Schedule Buffered Video PlaybackNuro · PHONE SCREENNuro interview questions
- Wallet Balance on a Selected DayBharatPe · PHONE SCREEN
- Calculate Server Shutdown PenaltyStripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions
- Hall of Shifting TilesAdobe · OAAdobe interview questions
- Weighted Lottery WinnersAmazon · ONSITE INTERVIEW
- Prefix Scores With the Running MaximumC3.ai · OAC3.ai interview questions
- Online No-Intercept Linear RegressionTwo Sigma · OATwo Sigma interview questions
- Array Challenge (QR Intern)Akuna Capital · OAAkuna Capital interview questions
- Range Negation UpdatesJP Morgan Chase · OAJP Morgan Chase interview questions
- Data UpdatesExpedia · OAExpedia 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)