FastPrepCode Editor Folding
Problems/Code Editor Folding

Code Editor Folding

Jane Street logoJane Street● MediumNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Jane Street new grad onsite interview. Our folding task is about 95% the same as the report. We state these directly: the brace assumptions, original indices, toggles that hide descendants, independent nested state, and the extension for display indices. We chose the fixed encoding of operations, the map of string pairs, the limits, and more examples.

Implement brace matching and code folding for a fixed list of source lines. Braces are balanced and properly nested. Every brace marks a code block. Each line has at most one brace, as its last non-whitespace character. A closing-brace line contains only indentation and }. All indices refer to the original source, starting at zero.

Every block starts expanded and keeps its own folded or expanded state. Toggling a parent block changes only that block’s state; all blocks inside it keep their states. You can also toggle a hidden inner block by using the index of its opening line in the original source.

For this exercise, process an ordered operation list and return one string-array row per operation:

  • MATCH: return each opening/closing line pair as opening:closing, ordered by opening index. These strings represent the brace-matching map.
  • TOGGLE i: switch the flag for opening line i, even if hidden. Return an empty row.
  • GET: return a new list of visible source lines in original order. For each visible folded block, keep its opening line through the {, append ... }, and omit subsequent lines through its matching closing line. Preserve every other visible line exactly.

The source may be empty. The original source is never modified. As an extension, explain how to map a current display-line index back to an original opening line before toggling; the operations in this problem still use original indices.

Function

codeEditorOperations(lines: String[], operations: String[]) → String[][]

Examples

Example 1

lines = ["def outer() {"," before();"," if (ready) {"," work();"," }"," after();","}","done();"]operations = ["MATCH","TOGGLE 2","GET","TOGGLE 0","GET","TOGGLE 0","GET"]return = [["0:6","2:4"],[],["def outer() {"," before();"," if (ready) { ... }"," after();","}","done();"],[],["def outer() { ... }","done();"],[],["def outer() {"," before();"," if (ready) { ... }"," after();","}","done();"]]

Nested state survives parent folding and expansion.

Example 2

lines = []operations = ["MATCH","GET"]return = [[],[]]

Empty source supports brace matching and an empty view.

Example 3

lines = ["{","}"]operations = ["GET","TOGGLE 0","GET","TOGGLE 0","GET"]return = [["{","}"],[],["{ ... }"],[],["{","}"]]

A two-line empty block folds and expands.

Constraints

  • 0 <= lines.length <= 500; each line has at most 100 characters, each a printable ASCII character (codes 32 through 126) or a horizontal tab (code 9). No other whitespace or line-break characters occur.
  • 1 <= operations.length <= 500; each operation has one documented form.
  • Every toggle index identifies an original opening-brace line.
  • Across all returned rows, the total number of characters is at most 20000.

More Jane Street interview questions

  • 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
  • Wizard Scroll Allocation StrategyONSITE INTERVIEW · Seen Oct 2026
  • Sort TradesPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
  • Order Matching EngineONSITE INTERVIEW · Seen Jul 2026
  • Order Book Data ValidationONSITE INTERVIEW · Seen Nov 2025
  • Biggest Daily Move and Longest Rising StreakOA · ONSITE INTERVIEW · Seen Apr 2021
  • Maximum-Scoring Consecutive Tree LevelsPHONE SCREEN · Seen Nov 2026

Similar questions at other companies

  • Text Document HistoryNotion · PHONE SCREEN · ONSITE INTERVIEWNotion interview questions
  • Multiline Text Editor with Cursor MovementDatologyAI · PHONE SCREEN
  • Text Editor, Part 2: Undo and RedoOpenAI · PHONE SCREENOpenAI interview questions
  • Text Editor OperationsMicrosoft · OAMicrosoft interview questions
  • File System Shell CommandsHarvey · ONSITE INTERVIEWHarvey interview questions
  • Adjacent Pair and Run RemovalWhatNot · PHONE SCREEN · ONSITE INTERVIEWWhatNot interview questions
  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
  • Stateful Log Transform and SearchRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
  • Query JSON Records with WHERE and ORDER BYGitHub · ONSITE INTERVIEW
  • Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW

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[][] codeEditorOperations(String[] lines, String[] operations) {
        // write your code here
    }
}
Checking account…