easy +10 pts

Parse markdown headers

Extract heading levels and texts from a markdown document.

Write a function `parse_markdown_headers(markdown: str) -> list[list[int, str]]` (or equivalently `list[tuple[int, str]]`) that takes a multi-line string containing markdown-formatted text and returns a list where each element is a pair of the heading level (an integer 1–6, equal to the number of leading '#' characters) and the heading text (a string). Only lines that start with 1 to 6 '#' characters followed by a space or end of line are considered headings. Lines that are not headings are ignored. Preserve the order in which headings appear. The heading text is the part after the leading hashes and the separating space, with leading/trailing whitespace trimmed, and any optional trailing hash characters (and the whitespace immediately before them) removed. If there are no headings, return an empty list.

Constraints

Input can be any string (including empty). Lines are separated by '\n'. Heading level is 1–6. The text may contain numbers, punctuation, spaces, and '#' characters (including those inside the text). Empty lines are skipped. The input string length is at most 10,000 characters. The solution should run within O(n) time and O(n) space.

Example

```python
>>> parse_markdown_headers('# Title')
[[1, 'Title']]
>>> parse_markdown_headers('## Section 1\nSome text\n### Subsection')
[[2, 'Section 1'], [3, 'Subsection']]
>>> parse_markdown_headers('### Title ###')
[[3, 'Title']]
>>> parse_markdown_headers('####### Not a heading')
[]
>>> parse_markdown_headers('')
[]
```
10 points ~15 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Split the input into lines using `split('\n')`.
For each line, count how many leading '#' characters exist; if the count is 0 or greater than 6, ignore the line.
After the leading hashes, there must be either a space or the end of the line. If there is a space, skip it and take the rest as raw text.
Trim the raw text, then remove all trailing '#' characters and any whitespace immediately before them. Finally trim again.
Store the result as `[level, cleaned_text]` pairs (lists, not tuples).
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.