data-structures · intermediate · ~15 min

Balanced brackets

Use a stack to match nested delimiters.

Challenge

Implement int paren_balanced(const char *s) returning 1 if every '(', '[', '{' is correctly matched and nested with its closer, else 0. Non-bracket characters are ignored.

Starter code

int paren_balanced(const char *s) {
    /* TODO */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.