Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. A string is valid if open brackets are closed by the same type of brackets in the correct order.
Simple valid: () → True
Input is_valid("()")
Output True
Mixed valid: ()[]{} → True
Input is_valid("()[]{}")
Output True
Invalid nesting: (] → False
Input is_valid("(]")
Output False
Nested valid: {[()]} → True
Input is_valid("{[()]}")
Output True
O(n)O(n)Ready to solve?
Open the code editor with the official template, run tests, and iterate.