Valid Bracket Sequence
Updated
Problem statement
Given a string s containing only the bracket characters ()[]{}, determine whether it is a valid bracket sequence.
Every opening bracket must be closed by the same bracket type, and closing brackets must appear in the reverse order of their matching openings. A closing bracket without a prior unmatched opening is invalid. The empty string is valid.
Function
isValidBracketSequence(s: String) → booleanExamples
Example 1
s = "([]){}"return = trueEach closer matches the newest unmatched opener of the same type.
Example 2
s = "([)]"return = falseThe closing parenthesis arrives while the square bracket is still open.
Example 3
s = "((("return = falseThree opening brackets remain unmatched.
Example 4
s = ""return = trueThere are no unmatched brackets in the empty sequence.
Constraints
0 <= s.length <= 100000.- Every character is one of
(,),[,],{, or}.
More NVIDIA Online Assessment questions
- Query a Header-Encoded MatrixOA · Seen Oct 2026
- Maximum ScoreOA · Seen Oct 2026
- Address on Same PageOA · Seen Oct 2026
- Minimize Task Resource ConsumptionOA · Seen Oct 2026
- Minimum Project Bid CostOA · Seen Oct 2026
- Count Ideal Numbers in a RangeOA · Seen Oct 2026
- Generate Bit MaskOA · Seen Oct 2026
- Reconstruct an Array from Prefix XOROA · Seen Oct 2026
- Sum of Subarray MinimumsOA · Seen Oct 2026
- Unique Integers That Sum to ZeroOA · Seen Oct 2026
Similar questions at other companies
- Valid ParenthesesByteDance · PHONE SCREENByteDance interview questions
- Valid ParenthesesCisco · PHONE SCREENCisco interview questions
- Stack Formula InterpreterTypeSafe AI · PHONE SCREEN
- Validate a Bracket SequenceInMobi · OAInMobi interview questions
- Validate a Bracket SequenceTripAdvisor · PHONE SCREEN
- Rich Text Parser Part 1 (Validate Tokens)Figma · PHONE SCREEN · ONSITE INTERVIEWFigma interview questions
- Valid ParenthesesBlackRock · OABlackRock interview questions
- Valid ParenthesesOracle · PHONE SCREENOracle interview questions
- Valid ParenthesesAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Valid ParenthesesVanguard · OAVanguard interview questions