Brackets that close in order
s is a line of text, such as a snippet of code. Return True if its brackets are well formed: every (, [ and { is closed later by a bracket of the same kind, and each closing bracket closes the most recently opened one that is still open. Characters other than ()[]{} don't matter, so a line without brackets is well formed.
Aim for one pass over s.
Besides the tests, one large input (30,000 nested brackets) with a ~200 ms limit (scaled to your device's speed): brute force won't pass.
Examples
brackets_ok("if (a[i] == b[0]) { go(); }")→truebrackets_ok("([)]")→falsebrackets_ok("{[()()]}")→true