Check for Balanced Parentheses
Learning DSA practice problem on Onlearn.
Difficulty: medium.
Topics: Check Balanced Parentheses in a String, Stack, Strings, Time Complexity, Space Complexity, time complexity analysis, string processing, stack algorithms, stack, Parentheses Parsing.
Problem Statement Given a string str containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if: 1. Open brackets must be closed by the same type of brackets. 2. Open brackets must be closed in the correct order. Note that an empty string is also considered valid. Input Specification The input will be a single string str. Output Specification Return True if the string is balanced, otherwise return False. Example 1: Input: str = "()[]{()}" Output: True Explanation: Every open bracket has its corresponding close bracket, and matching parentheses are in the correct order, hence they are balanced. Example 2: Input: str = "[()" Output: False Explanation: The opening bracket '[' does not have a matching closing bracket ']', hence it is not valid.