U

80. Valid Balanced Parentheses

Easy

Problem Description

Given a string SS containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if open brackets are closed by the same type of brackets in the correct order.

Input Format

A single line containing the bracket string SS.

Output Format

Print true if valid, else false.

Example 1:
Input:
()[]{}
Output:
true
Explanation: All brackets match and close properly.
Example 2:
Input:
(]
Output:
false
Explanation: Mismatched closing bracket ] for (.
Example 3:
Input:
([{}])
Output:
true
Explanation: Properly nested brackets.
Constraints:
  • Standard integer bounds: 32-bit signed integer or input range [1, 10^5].
  • Time complexity target: O(N) or O(N log N) where applicable.
  • Auxiliary space target: O(1) or minimal auxiliary memory.
Follow up:Can this algorithm be adapted to an online streaming setting where the entire input cannot be held in memory simultaneously?
1,180 Online