FastPrepValidate a Bracket Sequence
Problems/Validate a Bracket Sequence

Validate a Bracket Sequence

TripAdvisor logoTripAdvisor● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This exercise comes from a report of a first-round customized valid-parentheses task. The report did not keep the customization. So our version uses the usual three kinds of brackets, clear validity rules, limits, and fixed examples. It is about 72% the same as the reported question.

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) → boolean

Examples

Example 1

sequence = "([]{})"return = true

Every closing bracket matches the most recent unmatched opening bracket.

Example 2

sequence = "([)]"return = false

The 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.

Similar questions at other companies

  • Valid ParenthesesByteDance · PHONE SCREENByteDance interview questions
  • Valid ParenthesesCisco · PHONE SCREENCisco interview questions
  • Stack Formula InterpreterTypeSafe AI · PHONE SCREEN
  • Rich Text Parser Part 1 (Validate Tokens)Figma · PHONE SCREEN · ONSITE INTERVIEWFigma interview questions
  • Valid ParenthesesOracle · PHONE SCREENOracle interview questions
  • Valid ParenthesesAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Balanced Bracket String CheckRippling · PHONE SCREENRippling interview questions
  • Valid Bracket SequenceNVIDIA · OA · PHONE SCREENNVIDIA interview questions
  • Valid ParenthesesBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Valid ParenthesesPeopleStrong · PHONE SCREENPeopleStrong interview questions
See TripAdvisor hiring insights
Saved
class Solution {
    public boolean isValid(String sequence) {
      // Write your code here.
    }
}
Checking account…