Stack Discipline Target: 15s
Bracket matching is the classic stack application. Must be instant for interview warm-ups.
match = {'(': ')', '[': ']', '{': '}'}
stack = []
for c in s:
if c in match:
stack.append(match[c])
elif not stack or stack.pop() != c:
return False
return not stack
Type it from memory. Go.