Code RoomHeading outline faults
EasyPrep Room Coding #4716

Heading outline faults

CodingAlgorithms & data structuresEntry–Mid~12 min

A documentation site audits the heading outline of a page before publishing it. You receive the heading levels in reading order, 1 meaning h1 through 6 meaning h6, and the visible title of each heading in the same order. A heading is reported when its level is more than one deeper than the level of the heading immediately before it, which also makes any first heading below level 1 a fault, or when its title is empty or only whitespace. Compare every heading with the heading physically before it even when that one was itself reported, and treat a blank heading as a real heading for that comparison. A heading that breaks both rules is reported once. Return the 1-based positions of the reported headings in ascending order.

Implement
heading_outline_faults(levels: list[int], titles: list[str]) → list[int]
Examples
in[[1,2,3,2,1],["Getting started","Install","Requirements","Configure","Reference"]]out[]
in[[1,3,2],["Overview","Rate limits","Errors"]]out[2]
in[[1,2],["Billing"," "]]out[2]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 12 min
InputExpectedGot
[[1,2,3,2,1],["Getting started","Install","Requirements","Configure","Reference"]][]not run yetsample
[[1,3,2],["Overview","Rate limits","Errors"]][2]not run yetsample
[[1,2],["Billing"," "]][2]not run yetsample