Company: Visa_14feb
Difficulty: medium
Generate Table of Contents Problem Description You are given a document as an array of strings, text . Your task is to generate a Table of Contents (TOC) based on simple 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. Build the TOC using the following numbering scheme: 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. , ...). The final TOC should be returned as an array of strings where each entry is formatted as follows. 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" ) The title of