Rich Text Parser Part 1 (Validate Tokens)
Updated
Problem statement
🐝 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[]) → booleanExamples
Example 1
tokens = ["(", "a", "(", "b", ")", "c", ")"]return = trueThis 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 = falseThis is tokenize("(a,b,c"). The group is never closed.
Example 3
tokens = ["(", "a", "(", ")", ")", "(", "b", "c", ")", ")"]return = falseThis 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 Onsite Interview questions
- Recursive Display SortPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Rich Text Parser Part 3 (Depth Tokens)PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Rich Text Parser Part 2 (Parse Nested Groups)PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Table Selection and Color UpdatesPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
- Sort Documents Left to RightONSITE INTERVIEW · Seen Aug 2026
- Symmetric Binary TreeONSITE INTERVIEW · Seen Feb 2026
- Topmost Accessible NodesPHONE SCREEN · ONSITE INTERVIEW · Seen Jan 2025
- Nested Template Variable ExpansionONSITE INTERVIEW · Seen Jun 2024
- Parse, Validate, and Repair Markdown FormattingONSITE INTERVIEW · Seen Jun 2024
- Breadth-First Values of a Binary TreeONSITE INTERVIEW · Seen Oct 2022
Similar questions at other companies
- Stack Formula InterpreterTypeSafe AI · PHONE SCREEN
- Parse Boolean Rule ExpressionsStripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions
- Most Frequent Call Path From Function Trace LogsRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
- Single-Pass S-Expression ParserBaseten · ONSITE INTERVIEWBaseten interview questions
- Remove Parentheses from a Plus-Minus ExpressionOracle · PHONE SCREENOracle interview questions
- Decode StringCompass International Holdings · PHONE SCREENCompass International Holdings interview questions
- Flatten a Mixed JSON ListNike, Inc. · ONSITE INTERVIEWNike, Inc. interview questions
- Molecular Weight of a Grouped FormulaAgoda · ONSITE INTERVIEWAgoda interview questions
- Calculate a Token-List ExpressionCollege Vine · ONSITE INTERVIEW
- Evaluate a Parenthesized Integer ExpressionAdobe · PHONE SCREENAdobe interview questions