Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if: 1. Open brackets must be closed by the same type of brackets. 2. Open brackets must be closed in the correct order. 3. Every close bracket has a corresponding open bracket of the same type.
Example 1
Input: s = ({[]})[]
Output: true
Explanation: Every closing bracket matches the most recent unclosed opening bracket: ']' closes '[', '}' closes '{', ')' closes '(', and the final "[]" is a matching pair. Nothing is left open.
Example 2
Input: s = ()
Output: true
Explanation: The single '(' is closed by ')'.
Example 3
Input: s = ()[]{}
Output: true
Explanation: Each pair "()", "[]" and "{}" opens and closes immediately with a matching bracket.
Brackets have LIFO structure: the latest opener must be the next to close. A stack models that exactly. Push each opener; on a closer, verify the top matches.
Run checks all cases above. Submit evaluates all test cases.