FastPrepRich Text Parser Part 3 (Depth Tokens)
Problems/Rich Text Parser Part 3 (Depth Tokens)

Rich Text Parser Part 3 (Depth Tokens)

Figma logoFigma● MediumFULLTIMEPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This set reconstructs a Figma full-time coding screen for a machine learning role that a candidate described first-hand; the depth-token format and its example come from that account. The candidate recalled this last part less clearly than the first two and leaned on the interviewer for details, so the starting-depth, depth-jump and sibling rules are spelled out here and boundary tests were added. A community sighting submitted for Part 1 places the same series in a full-time software engineering phone screen on CoderPad on October 13, 2026.

A second candidate described a full-stack CoderPad screen at Figma in October 2026 built on the same parsing questions. In that version the parser returned objects for text and groups, and flat input, with every word at the top level, was part of what the closing question tested. When a reader wrote the depth format out with 0 for words at the top level, so that an all-zero stream yields a plain list, the candidate agreed it was the same task. That report does not list its tests, and the candidate did not finish one case of that last question.

Practice choices: falling to depth 0 closes every open group, so a later positive depth starts a fresh top-level group; the answer keeps the nested-list string used by the earlier parts instead of objects; depths run from 0 to 50 and the other limits are ours. Example 5 is the reader's all-zero example written with string tokens; Example 6 is ours.

This part is estimated to match the reports at about 85%.

Special thanks: 🌷 A special thank you to our lovely, amazing frenz for sharing interview sightings for this series on October 13, 2026! ദ്ദി ˉ͈̀꒳ˉ͈́ )✧ 💚

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

Part 3. This was the final twist of the real interview. After the Part 2 parser passed, the interviewer swapped the tokenizer for a different implementation and asked for the same result. The new tokenizer returns a flat list in which every word is preceded by its nesting depth: tokenize("(a,(b),c)") now returns [1, 'a', 2, 'b', 1, 'c']. There are no bracket tokens anymore.

The final question adds one more requirement: the parser must also accept a stream with no nesting, in which top-level words carry depth 0.

Implement readRichText(tokens) that produces the same serialized nested structure that Part 2 produced, from this new token format. On FastPrep the flat list arrives as string tokens: depths appear as strings such as "1", each followed by its word.

Rules of the depth encoding.

  • depths are non-negative integers. Depth 0 means the word sits directly in the document, outside every group, so a stream whose depths are all 0 has no nesting at all. The first depth may be greater than 1
  • between consecutive words the depth may rise or fall by more than 1: each unit of rise opens one new group, each unit of fall closes one
  • consecutive words at the same depth are siblings in the same group, and a word that returns to a still-open depth joins that open group
  • falling to depth 0 closes every open group, so a later positive depth opens a new top-level group instead of reopening an earlier one
  • this encoding cannot represent empty groups, so none appear

Output format. Return the parsed document as a Python-style list string:

  • a group serializes as [ … ] with children joined by a comma and a single space
  • words are wrapped in single quotes
  • the return value is the serialization of the document: the list of all top-level items. A document that consists of one group therefore starts with two brackets, e.g. [['a', 'b', 'c']], while a stream with no nesting returns a flat list such as ['a', 'b']

In Python, str(nested_list) produces exactly this format.

Function

readRichText(tokens: String[]) → String

Examples

Example 1

tokens = ["1", "a", "1", "b", "1", "c"]return = "[['a', 'b', 'c']]"

All words have depth 1, so they belong to the same top-level group: ['a', 'b', 'c']. The full parsed document is [['a', 'b', 'c']].

Example 2

tokens = ["1", "a", "2", "b", "1", "c"]return = "[['a', ['b'], 'c']]"

This is tokenize("(a,(b),c)") from Part 3. The word b has depth 2, so it becomes a nested group between a and c.

Example 3

tokens = ["3", "a", "2", "b", "1", "c"]return = "[[[['a'], 'b'], 'c']]"

This is read_rich_text(tokenize("(((a)b)c)")) from Part 2. The first depth is 3, so a sits inside three groups; the depths then fall to 2 and 1, closing one level each time. Together with the outer document list the answer has four leading brackets.

Example 4

tokens = ["1", "a", "3", "b"]return = "[['a', [['b']]]]"

Only words carry depth labels, so the depth can jump from 1 straight to 3: two new groups open at once and b lands inside both.

Example 5

tokens = ["0", "a", "0", "b"]return = "['a', 'b']"

Both words have depth 0, so neither sits inside a group: the stream has no nesting and the document is the flat list ['a', 'b'].

Example 6

tokens = ["0", "a", "1", "b", "2", "c", "0", "d", "1", "e"]return = "['a', ['b', ['c']], 'd', ['e']]"

a is a top-level word. The rise to 1 opens a group for b, and the rise to 2 opens a group inside it for c. Falling to 0 closes both groups, so d is top-level again, and the final rise to 1 opens a new group for e rather than reopening the first one.

Constraints

  • 0 <= tokens.length <= 5000, always an even number: alternating depth and word
  • depths are decimal strings between 0 and 50
  • words are lowercase alphanumeric with at most 10 characters

More Figma Onsite Interview questions

  • Recursive Display SortPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Rich Text Parser Part 2 (Parse Nested Groups)PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Rich Text Parser Part 1 (Validate Tokens)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

  • 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
  • Parse Nested HTML into a TreeApple · ONSITE INTERVIEWApple interview questions
  • Calculator with ParenthesesGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Lisp Expression ParserAmazon · ONSITE INTERVIEW

Figma interview experiences

  • Figma interviews · November 2026
  • Figma SWE Intern OA and Final Round: 21 Experiences
  • Figma SWE Intern OA Questions: 25 Experiences
All Figma interview questionsSee Figma hiring insights
Saved
class Solution {
    public String readRichText(String[] tokens) {
      // write your code here
    }

}
Checking account…