Reported January 2026
JP Morgansimulation

Generate Table of Contents

Reported by candidates from JP Morgan's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live JP Morgan OA. Under 2s to a working solution.
Founder's read

JP Morgan hit you with a parsing problem in January 2026, and it's straightforward once you see the pattern. You're building a table of contents from a document array. Chapters get sequential numbers (1, 2, 3...), sections get dotted notation tied to their chapter (1.1, 1.2, 2.1...). Extract the markers, renumber them, return the formatted result. StealthCoder catches the edge case you blank on during the live OA.

The problem

You are given a document as an array of strings. Build a table of contents using chapter numbers 1, 2, 3,... and section numbers such as 1.1, 1.2, 2.1, and so on. Return the result as a String[]. Only chapter and section markers contribute to the table of contents, and sections are numbered relative to the latest chapter.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is state management. You iterate through the document, identify chapter and section markers (usually by prefix or tag), track the current chapter number, and reset section counts when you move to a new chapter. Most candidates overcomplicate the parsing or forget to reset section numbers. The common pitfall: hardcoding marker logic without checking the actual format in the problem statement. If the input uses something like '[Chapter]' or 'CHAPTER:', you need to handle that exact format. StealthCoder reads your screen in real time, so if you freeze on the marker format during the assessment, it surfaces the pattern instantly.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill Generate Table of Contents cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass JP Morgan's OA.

JP Morgan reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Generate Table of Contents FAQ

How do I know what counts as a chapter vs. section marker?+

The problem statement defines it. Typically chapters are marked one way (e.g., all caps, specific prefix) and sections another. Read the examples in the OA carefully. If the input shows '[Chapter: Title]' vs '[Section: Title]', parse those exact strings. Don't assume.

Do I need to extract and clean the marker text?+

Yes. You extract the marker, assign it the correct number (1, 1.1, 2, 2.1, etc.), then likely format it back into a readable string. Check the expected output format in the OA. Usually it's 'Chapter 1', 'Section 1.1', or similar.

What if the document has a chapter with no sections?+

That's fine. Just output the chapter number. Section counter only increments when you see a section marker. When you hit the next chapter, reset the section counter to 0 so the first section under it becomes X.1.

Can I solve this in one pass?+

Yes. Single iteration through the array. Track current chapter and section numbers. When you see a chapter marker, increment chapter and reset section to 0. When you see a section marker, increment section. Append formatted strings to your result.

Is this problem still asked at JP Morgan?+

It was reported in January 2026. Parsing and state tracking are core JP Morgan assessments. If you see a similar 'number and format document structure' problem, same approach applies. Master the marker detection and counter reset logic.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with JP Morgan.

OA at JP Morgan?
Invisible during screen share
Get it