Menu
Coddy logo textTech

Practice #3

Lesson 11 of 13 in Coddy's Stack - Data Structures Series #1 course.

The next challenges are designed to use stack in them.

The Stack data structure (storing characters) is already provided for you — use it!

challenge icon

Challenge

Easy

Write a function isBalancedParentheses that gets a string of parentheses, brackets, and braces and returns true if the string is balanced, otherwise false.

That is, every opening symbol must have a corresponding closing symbol.

Use the provided Stack to solve this problem!

Examples:

Input: "({[]})" → Output: true

Input: "({[)})]" → Output: false

Try it yourself

#include <stdio.h>
#include <string.h>
#include "solution.h"

int main() {
    char s[1000];
    if (fgets(s, sizeof(s), stdin) == NULL) {
        s[0] = '\0';
    }
    s[strcspn(s, "\r\n")] = '\0';
    printf("%s\n", isBalancedParentheses(s) ? "true" : "false");
    return 0;
}

All lessons in Stack - Data Structures Series #1