Valid Parentheses
Problem Statement
Valid Parentheses is a fundamental problem in parsing and validating string input. Given a string of characters containing various types of parentheses (round, square, curly), determine if the string of parentheses is valid.
A string of parentheses is valid if every opening parenthesis has a corresponding and matching closing parenthesis which is nested inside it in the correct order.
The allowed pairs of parentheses are:
,
, and
.
Rules and Constraints
- The input string is composed of only the three types of parentheses.
- The string may be empty.
- The solution must determine the validity of the string in O(n) time complexity, where n is the length of the input string.
- The solution must use O(n) space complexity in the best case scenario, i.e., the string is empty or the parentheses are balanced.
- The solution must return if the string of parentheses is valid, and otherwise.
Input/Output Specifications
- Input: A string of characters containing various types of parentheses.
- Output: A boolean value indicating whether the string of parentheses is valid.
Example
Input: {"s":"()[]{}"}
Output: true