Walks the string one character at a time, tracking the open ( and [ depth as tuple
lengths (Parens / Brackets). Written as a tail-recursive conditional type so TypeScript's
tail-call optimisation can handle long inputs — the longest of the supplied examples is ~357
characters, comfortably under the ~1000-step limit.
Resolves to true only when every character is legal, every close has a matching open, and
both stacks are empty at the end. Any illegal character or unbalanced delimiter short-circuits
to false.
Walks the string one character at a time, tracking the open
(and[depth as tuple lengths (Parens/Brackets). Written as a tail-recursive conditional type so TypeScript's tail-call optimisation can handle long inputs — the longest of the supplied examples is ~357 characters, comfortably under the ~1000-step limit.Resolves to
trueonly when every character is legal, every close has a matching open, and both stacks are empty at the end. Any illegal character or unbalanced delimiter short-circuits tofalse.