Validate a Bracket Sequence
Updated
Problem statement
Given a string sequence containing only the bracket characters ()[]{}, return whether it is valid.
A valid sequence closes every opening bracket with the same bracket type, and closes brackets in the reverse order in which they were opened.
Function
isValid(sequence: String) → booleanExamples
Example 1
sequence = "([]{})"return = trueEvery closing bracket matches the most recent unmatched opening bracket.
Example 2
sequence = "([)]"return = falseThe closing parenthesis appears before the nested square bracket closes.
Constraints
0 <= sequence.length <= 100000.- Every character is one of
(,),[,],{, or}.
Source note: The source image is a source-neutral excerpt of the author-reported prompt.
More InMobi Online Assessment questions
- Count Substrings Matching with One Adjacent SwapOA · Seen Oct 2026
- Maximum Subarray with Start and End WindowsOA · Seen Oct 2026
- Minimum Service Cold StartsOA · Seen Oct 2026
- Range Maximum Subarray Sum QueriesOA · Seen Oct 2026
- Connected Components with Divisor ThresholdOA · Seen Aug 2026
- Maximize Impression ValueOA · Seen Aug 2026
- Supply Path OptimizationOA · Seen Aug 2026
- Delivery ServiceOA · Seen Jun 2026
- Shared InterestOA · Seen Jun 2026
- Temporal AnomaliesOA · Seen Jun 2026
Similar questions at other companies
- Valid ParenthesesBlackRock · OABlackRock interview questions
- Valid ParenthesesVanguard · OAVanguard interview questions
- Valid Bracket SequenceNVIDIA · OA · PHONE SCREENNVIDIA interview questions
- Get Final StringIBM · OAIBM interview questions
- Backspace String CompareGoldman Sachs · OAGoldman Sachs interview questions
- The PromHackerEarth · OA
- Compare Character Arrays with BackspacesOdoo · OAOdoo interview questions
- Eliminate SubstringJP Morgan Chase · OAJP Morgan Chase interview questions
- Balancing ParenthesesOracle · OAOracle interview questions
- Balanced Brackets in an ExpressionBank of America · OABank of America interview questions