Problem Β· Parsing

Rich Text Parser Part 1 (Validate Tokens)

Learn this problem
● EasyFigmaONSITE INTERVIEW

Problem statement

πŸ“ Source note, July 7, 2026: This set reconstructs a real Figma MLE full-time coding screen, shared first-hand by a candidate. For this part, the seven pass/fail streams you'll be graded on are the interviewer's own test cases, word for word, so what's graded is a 100% match. The prompt text around them was thinner in the original account, so FastPrep wrote the framing and constraints. As a whole we'd call this page a 95% match. If you've met this question in an interview and remember it differently, tell us and we'll tighten it. Thank you! 🐝

🐝 Hi there! The description you are currently reading is one part of a 3-part Figma interview set. It is highly recommended to read ALL THE PARTS before coding as parts build on top of each other 🐳

  • Rich Text Parser Part 1 (Validate Tokens) πŸ¦”
  • Rich Text Parser Part 2 (Parse Nested Groups) 🐹
  • Rich Text Parser Part 3 (Depth Tokens) 🦚
  • At Figma, documents are stored as nested structures: a paragraph can contain text runs and nested groups, which can themselves contain more groups. You are working with a small text format that describes structures like this. This set reconstructs a real ~45-minute Figma coding screen, part by part.

    Setup. The interview starts from a tokenizer that is already written for you. For example, tokenize("(a,b,c)") returns ["(", "a", "b", "c", ")"]. Notice that commas are separators: the tokenizer drops them, so every token you receive is "(", ")", or a word. On FastPrep the tokenizer's output is handed to you directly as the tokens array.

    Part 1. Before parsing anything, the interviewer asks for a validator. Implement isWellFormed(tokens) that returns true when the bracket structure of the token stream is well-formed: scanning left to right, no ")" ever appears without a matching earlier "(", and every "(" is eventually closed.

    Words never affect validity and may appear anywhere, including outside all groups. A stream with no tokens is well-formed. Multiple separate groups at the top level are allowed.

    Function

    isWellFormed(tokens: String[]) β†’ boolean

    Examples

    Example 1

    tokens = ["(", "a", "(", "b", ")", "c", ")"]return = true

    This is tokenize("(a,(b),c)"). The inner group closes before the outer one; every open has a matching close.

    Example 2

    tokens = ["(", "a", "b", "c"]return = false

    This is tokenize("(a,b,c"). The group is never closed.

    Example 3

    tokens = ["(", "a", "(", ")", ")", "(", "b", "c", ")", ")"]return = false

    This is tokenize("(a,())(b,c))"). Everything up to (b,c) is balanced, but the final ")" has no matching open.

    Constraints

    • 0 <= tokens.length <= 5000
    • each token is "(", ")", or a lowercase alphanumeric word with at most 10 characters

    More Figma problems

    drafts saved locally
    public boolean isWellFormed(String[] tokens) {
      // write your code here
    }
    
    tokens["(", "a", "(", "b", ")", "c", ")"]
    expectedtrue
    checking account