Problem title
Difficulty
Avg time to solve

Maximum Path Sum in the matrix
Moderate
35 mins
Rotate Matrix
Moderate
15 mins
Partitions With Given Difference
Moderate
--
Valid Parentheses
Easy
10 mins
Print Like A Wave
Easy
20 mins
Chess Tournament
Easy
20 mins
Overlapping ABBA
Easy
10 mins
Maximum of minimum for every window size
Hard
45 mins
Placment Of students
Moderate
15 mins
Unique Paths
Moderate
25 mins
48

Valid Parentheses

Difficulty: EASY
Contributed By
Avg. time to solve
10 min
Success Rate
80%

Problem Statement

You're given string ‘STR’ consisting solely of “{“, “}”, “(“, “)”, “[“ and “]” . Determine whether the parentheses are balanced.

Input Format:
The first line contains an Integer 'T' which denotes the number of test cases or queries to be run. Then the test cases follow.

The first and the only line of input of each test case contains a string, as described in the task.
Output format :
For each test case, the first and the only line of output prints whether the string or expression is balanced or not.

The output of every test case is printed in a separate line.
Note:
You are not required to print anything explicitly. It has already been taken care of. Just implement the given function.
Constraints:
1 <= T <= 10
1 <= N <= 10^5

Where N is the length of the input string or expression.

Time Limit: 1 sec
Sample Input 1 :
2
[()]{}{[()()]()}
[(])
Sample Output 1 :
Balanced
Not Balanced
Explanation Of the Sample Input 1 :
In TestCase 1 there is always an opening brace before a closing brace i.e ‘{‘ before ‘}’, ‘(‘ before ‘)’, ‘[‘ before ‘]’.

In TestCase 2 there is closing brace for ‘[‘ i.e. ‘]’ before closing brace for ‘(‘ i.e. ‘)’. The balanced sequence should be ‘[()]’.
Sample Input 2 :
2
[[}[
[]{}()
Sample Output 2 :
Not Balanced
Balanced
Explanation Of the Sample Input 2 :
In TestCase 1 there is no opening brace before a closing brace i.e no ‘{‘ for ‘}’.

In TestCase 2 there is exactly one closing for each opening braces and each closing brace is after their corresponding opening brace.
Reset Code
Full screen
copy-code
Console