Company: Visa_14feb
Difficulty: medium
Generate Table of Contents Problem Description You're given a document represented as an array of strings, text . Build a Table of Contents (TOC) out of it using a small set of markup rules. The markup rules are as follows: A chapter is any line starting with # . A section is any line starting with ## and belongs to the most recent chapter. All other lines must be ignored. Number entries in the TOC as follows: Chapters are numbered sequentially starting from 1 (e.g., 1. , 2. , 3. , ...). Sections are numbered relative to their chapter, restarting from 1 for each new chapter (e.g., 1.1. , 1.2. , 2.1. , ...). Return the TOC as an array of strings, with each entry formatted as shown below. Note that the number is followed by a period and a single space. Chapter entries: "<chapter_number>. <Chapter Title>" (e.g., "1. Algorithms" ) Section entries: "<chapter_number>.<section_number>. <Section Title>" (e.g., "1.1. Sorting" ) A chapter's or section's title is wha