You’re interviewing for a backend or data engineering role at a FAANG-level company. The interviewer describes a real product scenario:
A large platform processes structured text such as configuration files, query expressions, templates, or code snippets. These inputs often contain parentheses, brackets, and braces that must be correctly nested and closed to avoid parsing errors or system failures.
The system represents such an input as a string s consisting only of parentheses characters. Before further processing, the platform needs to verify whether the structure is syntactically valid.
This is a common practice coding problem for DSA question might ask in Google, Amazon, Netflix, Meta, Apple, Microsoft, Uber, and Bloomberg interviews.
Your Task
Given a string s containing only the characters '(', ')', '{', '}', '[', and ']', determine whether the input string is valid.
A string is valid if:
- Open brackets are closed by the same type of brackets
- Open brackets are closed in the correct order
- Every closing bracket has a corresponding opening bracket
Input Format
s: a string containing only parentheses characters
Output Format
- A boolean value
true if the string is validfalse otherwise