164. Balanced Paranthesis

Given string str containing just the characters '(', ')', '{', '}', '[' and ']', check if the input string is valid and return true if the string is balanced otherwise return false.

Example 1:

Input: str = “()[{}()]”

Output: True

Explanation: As every open bracket has its corresponding close bracket. Match parentheses are in correct order hence they are balanced.

Example 2:

Input: str = “[()”

Output: False

Explanation: As ‘[‘ does not have ‘]’ hence it is not valid and will return false.

Now Your Turn!

Pick the correct output for the given input

Input: str = "{[()]}"

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

1 <= str.length <= 104

str consists of parentheses only '()[]{}'.

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

Fun Facts

0
class Solution {
public:
bool isValid(string str) {
}
};
Test Case

Input:

N
Str