101. Valid Brackets

Acceptance — 0 accepted 0 submissions

Medium
StackStrings
No companies listed
A code editor highlights mismatched brackets. A bracket string is valid if:
• every opening bracket ( [ { is closed by the same type of bracket
• brackets close in the correct order

Check whether the given string of brackets is valid.

Input Format
A single string made of the characters ( ) [ ] { }.

Output Format
Print Valid or Invalid.

Constraints
• 1 ≤ length ≤ 10^4

Example 1

Input
()[]{}
Output
Valid

Explanation Each pair opens and closes properly.

Example 2

Input
([{}])
Output
Valid

Explanation Nested correctly, inside-out.

Example 3

Input
(]
Output
Invalid

Explanation ( is closed by ], which is the wrong type.

Example 4

Input
((
Output
Invalid

Explanation Two brackets are never closed.

Acceptance —
Accepted 0
Submissions 0
Auto-save
Saved Ln 1, Col 1
Submit a solution to see its status here.
Input
Expected Output
Valid
No results yet
Run your code to test it against the sample cases.
Problem List