FastPrepNested Template Variable Expansion
Problems/Nested Template Variable Expansion

Nested Template Variable Expansion

Figma logoFigma● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report describes variable substitution, singular and plural wording, and nested variables. We chose the placeholder syntax, the rule that references cannot loop, and the exact plural output. Our version is about 87% the same as the reported question.

Render a text template using named variables. Each row of variables is [name, value].

The template and variable values may contain two placeholder forms:

  • {name} inserts the fully expanded value of that variable.
  • {name|singular|plural} requires the fully expanded value of name to be a non-negative integer. It inserts the number, one space, and singular when the number is 1; otherwise it inserts the number, one space, and plural.

Variable values may reference other variables. Expand them recursively, then render the input template.

Function

renderTemplate(text: String, variables: String[][]) → String

Examples

Example 1

text = "I like {animal}."variables = [["animal","dogs"]]return = "I like dogs."

The simple placeholder is replaced by the value of animal.

Example 2

text = "Adopt {count|dog|dogs}."variables = [["count","1"]]return = "Adopt 1 dog."

The numeric value is exactly 1, so the singular form is selected.

Example 3

text = "{greeting} You have {count|message|messages}."variables = [["name","Mina"],["greeting","Hello, {name}!"],["rawCount","2"],["count","{rawCount}"]]return = "Hello, Mina! You have 2 messages."

Both greeting and count expand through another variable before the outer template is rendered.

Constraints

  • 1 <= template.length <= 200000.
  • 1 <= variables.length <= 100000.
  • Variable names are unique and contain only ASCII letters, digits, and underscores.
  • Every referenced variable exists, references are acyclic, and nesting depth is at most 1000.
  • Singular and plural labels are non-empty and contain no braces or |.
  • The rendered output length is at most 10^6.

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
  • 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
  • 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

  • Spreadsheet Formula DependenciesAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
  • Resolve Variable Equations with Dependency ErrorsApplied Intuition · PHONE SCREENApplied Intuition interview questions
  • Resolve Variable Equations with Dependency ErrorsMotive · PHONE SCREENMotive interview questions
  • Spreadsheet With Dependent CellsCharacter.AI · PHONE SCREEN
  • Feature Flags with Rules, Dependencies and ExposurePerplexity AI · ONSITE INTERVIEWPerplexity AI interview questions
  • Invoice / Payment ReconciliationStripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions
  • Template Variable ExpansionGoogle · ONSITE INTERVIEWGoogle interview questions
  • JSON Path Lookup with Implicit Array WildcardsMongoDB · ONSITE INTERVIEWMongoDB interview questions
  • Transform Dotted Keys into a Nested MapProofpoint · ONSITE INTERVIEW
  • Serialize and Deserialize a String Key-Value StoreByteDance · ONSITE INTERVIEWByteDance interview questions

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 renderTemplate(String text, String[][] variables) {
        // Write your code here.
    }
}
Checking account…