Problem. Given a string s made of the characters ()[]{}, return whether it is valid: every opening
bracket is closed by the same type, in the correct order, and every closing bracket has a matching opener.
"()[]{}" → True
"{[()]}" → True
"([)]" → False (the ] closes a [ while a ( is still open inside it)
"((" → False
ML context. Structured output from a language model (JSON, a tool call, a code snippet) is useless if it is unbalanced. Checking bracket nesting is the cheapest first test, it tells you where generation went wrong, and constrained decoding uses the same stack to know which closing bracket is allowed next. Config parsers and expression evaluators (lesson 6.6) run on the same idea.