Given a bracket sequence of length L, you are to determine if it is valid!
A valid bracket sequence is defined recursively as:
However, two other pairs of brackets can be found in the bracket sequence, '[' which is to be matched with ']' and '{' which is to be matched with '}'.
For all tests: each character will be one of the following: '(', ')', '[', ']', '{', '}'.
Subtask 1 (10%): 1 ≤ L ≤ 4.
Subtask 2 (30%): 1 ≤ L ≤ 1000.
Subtask 3 (20%): 1 ≤ L ≤ 100000. However, each character will be either '(' or ')'.
Subtask 4 (40%): 1 ≤ L ≤ 100000.
Subtask 5 (0%): Sample Testcases.
The first line of input will contain one integer, L.
The second line of input will contain one string, the bracket sequence.
The output should contain one string, either "Valid" or "Invalid".
6 ([]{})
Valid
8 (())((()
Invalid
6 ([}{])
Invalid
Subtask | Score |
---|---|
1 | 10 |
2 | 30 |
3 | 20 |
4 | 40 |
5 | 0 |