Company: Hackerrank_Forward deploy engineer_26june
Difficulty: medium
You are given a document as an array of strings. Your task is to generate a Table of Contents (TOC) based on simple markup rules: 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: Chapters: 1., 2., 3., ... Sections: 1.1., 1.2., 2.1., etc. (chapter number first, then section number) Output the TOC as an array of strings where: Chapter entries look like: "1. Title" Section entries look like: "1.1. Title" Example Suppose text contains 12 strings: "# Algorithms" "This chapter covers the most basic algorithms." "### Sorting" "Quicksort is fast and widely used in practice" "Merge sort is a deterministic algorithm" "### Searching" "DFS and BFS are widely used graph searching algorithms" "Some variants of DFS are also used in game theory applications" &q