← Stack Discipline

Micro-Drill #35 — Check balanced parens

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.

Practice Problems

Related Coding Drills

← Micro #34 Micro #36 →