Valid Parentheses
Updated
Problem statement
Given a string s containing only the bracket characters (, ), [, ], {, and }, determine whether it is valid.
A string is valid when every opening bracket is closed by the same type of bracket and brackets close in the reverse order in which they were opened. The empty string is valid.
Return true if s is valid; otherwise, return false.
Function
isValidParentheses(s: String) → booleanExamples
Example 1
s = "()[]{}"return = trueEach opening bracket is immediately followed by its matching closing bracket.
Example 2
s = "([{}])"return = trueThe brackets are properly nested and close in reverse opening order.
Example 3
s = "([)]"return = falseThe closing parenthesis appears before the nested square bracket is closed.
Constraints
0 <= s.length <= 100000.- Every character of
sis one of()[]{}.
Source note: The prompt excerpt names parenthesis matching with a stack. The practice contract supplies the conventional bracket alphabet and edge cases omitted from the report.
More Amazon Phone Screen questions
- Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Search in a Rotated Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent ElementsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Minimum Time to Spread Through a GridPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Consistent-Hash Packet RouterPHONE SCREEN · Seen Nov 2026
- Count Connected ComponentsPHONE SCREEN · Seen Nov 2026
- Second Largest Distinct ElementPHONE SCREEN · Seen Nov 2026
- Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Valid ParenthesesByteDance · PHONE SCREENByteDance interview questions
- Valid ParenthesesCisco · PHONE SCREENCisco interview questions
- Valid ParenthesesMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Stack Formula InterpreterTypeSafe AI · PHONE SCREEN
- Valid ParenthesesEPAM · ONSITE INTERVIEWEPAM interview questions
- Valid ParenthesesQualys · ONSITE INTERVIEWQualys interview questions
- Validate a Bracket SequenceTripAdvisor · PHONE SCREEN
- Rich Text Parser Part 1 (Validate Tokens)Figma · PHONE SCREEN · ONSITE INTERVIEWFigma interview questions
- Valid ParenthesesOracle · PHONE SCREENOracle interview questions
- Valid ParenthesesKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions