Mail merge nesting
A mail merge template is compiled from a flat list of block markers. Every entry in markers reads either "open|loop" or "close|loop", where the text after the pipe is the block name, and block names may repeat. A template compiles when each open is closed by a close carrying the same name, and blocks close in the reverse order they opened, so a block opened inside another must close before the outer one does. Return -1 when the whole list compiles. Otherwise return the position of the first entry the compiler cannot accept, meaning a close that names something other than the innermost block still open, or a close arriving while no block is open. When the list runs out with blocks still open, return the position of the earliest marker still open. An empty list compiles.
template_nesting_fault(markers: list[str]) → int[["open|loop","open|if","close|if","close|loop"]]out-1[["open|loop","close|if"]]out1[["open|header","open|row"]]out0State 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.
[["open|loop","open|if","close|if","close|loop"]]-1not run yetsample[["open|loop","close|if"]]1not run yetsample[["open|header","open|row"]]0not run yetsample