Valid Parentheses
Updated
Problem statement
Given a string s containing only ()[]{}, determine whether its brackets are balanced. Every closing bracket must match the most recent unmatched opening bracket of the same type, and every opening bracket must be closed.
For this exercise, assume the empty string is valid. Return a boolean.
Function
validParentheses(s: String) → booleanExamples
Example 1
s = "([]){}"return = trueEach pair has the correct type, and the square brackets close before their enclosing parentheses.
Example 2
s = "([)]"return = falseThe first closing parenthesis encounters an unmatched opening square bracket, so the nesting is invalid.
Constraints
- For this exercise, assume
0 <= s.length <= 10^5. - Every character is one of
( ) [ ] { }.
More PeopleStrong Phone Screen questions
- Reverse Linked-List Nodes in Groups of KOA · PHONE SCREEN · Seen Mar 2026
- Level of the Minimum-Sum SubtreePHONE SCREEN · Seen Jan 2026
- Ceiling Value in a Sorted ArrayPHONE SCREEN · Seen Sep 2025
- Maximum Employee Salary for a CompanyPHONE SCREEN · Seen Sep 2025
- Number of ProvincesPHONE SCREEN · Seen May 2025
- Shortest Subarray with an Exact Target SumPHONE SCREEN · Seen May 2025
- Add Forward Linked-List Numbers Using RecursionPHONE SCREEN · Seen Oct 2021
- Running Median of a StreamPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2021
- Build an Expression Tree from PostfixPHONE SCREEN · Seen Oct 2021
- Maximum Score from Deleting Neighboring ValuesPHONE SCREEN · Seen Oct 2021
Similar questions at other companies
- Valid ParenthesesByteDance · PHONE SCREEN
- Valid ParenthesesCisco · PHONE SCREEN
- Stack Formula InterpreterTypeSafe AI · PHONE SCREEN
- Validate a Bracket SequenceTripAdvisor · PHONE SCREEN
- Rich Text Parser Part 1 (Validate Tokens)Figma · PHONE SCREEN · ONSITE INTERVIEW
- Valid ParenthesesOracle · PHONE SCREEN
- Valid ParenthesesAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Balanced Bracket String CheckRippling · PHONE SCREEN
- Valid Bracket SequenceNVIDIA · OA · PHONE SCREEN
- Valid ParenthesesBloomberg LP · PHONE SCREEN · ONSITE INTERVIEW