JPMorgan ChaseOA #16
Generate Table of Contents
Estimated EasyJudge-ready
Topics (AI-labelled)StringsSimulation
Lines that start strictly with "# " are chapters, lines that start with "## " are sections, and all other lines are ignored; the first valid heading is guaranteed to be a chapter. Chapters are numbered from 1, and section numbers restart from 1 in each new chapter. Only the fixed marker prefix is removed; titles are not trimmed. If there are no valid headings, the table of contents is empty.
Input
The input is a JSON array of strings; 1≤number of lines≤1000, and each line has 1..100 Unicode code points. The original does not restrict the character set; JSON escapes preserve NUL, newlines, and other control characters, and empty titles are allowed.
Output
Output a single-line canonical JSON array followed by a newline; an empty table of contents is []. Put one space after each comma; output non-ASCII characters directly; escape double quotes and backslashes; use \b/\t/\n/\f/\r for backspace/tab/newline/form feed/carriage return, use lowercase four-digit \u00xx for the rest of U+0000..U+001F, and do not escape slashes. This matches Python json.dumps(result, ensure_ascii=False); the checker is exact.
Example 1
Input:
["# Algorithms", "text", "## Sorting", "## Searching", "# Data Structures"]
Output:
["1. Algorithms", "1.1. Sorting", "1.2. Searching", "2. Data Structures"]
Example 2
Input:
["body", "# A ", "## \t B ", "# "]
Output:
["1. A ", "1.1. \t B ", "2. "]
Example 3
Input:
["ordinary text"]
Output:
[]
Example notes
The outputs of the three public examples are, in order: ["1. Algorithms", "1.1. Sorting", "1.2. Searching", "2. Data Structures"]; ["1. A ", "1.1. \t B ", "2. "]; []. These answers have been checked by independent enumeration or direct simulation.
Editorial
Loading solution…