Validate a Balanced INDENT and DEDENT Token Stream

Last updated: July 21, 2026

Quick Overview

The question asks the candidate to validate a stream of INDENT and DEDENT tokens to ensure they are balanced and correctly nested.

Figma
Coding & Algorithms
Software Engineer
Figma
July 21, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

10

0

102 solved


The question asks the candidate to validate a stream of INDENT and DEDENT tokens to ensure they are balanced and correctly nested.

This question is typically asked during the onsite interview round for software engineering candidates at Figma. The interviewer is evaluating the candidate's problem-solving skills, understanding of data structures, and ability to write clean, efficient code. It also assesses the candidate's approach to handling edge cases and their ability to explain their thought process clearly.

What the Interviewer Expects
  • Clearly define the problem and constraints.
  • Use an appropriate data structure, such as a stack, to track INDENT and DEDENT tokens.
  • Handle edge cases, such as unmatched tokens or consecutive INDENTs.
  • Provide a correct and efficient algorithm with a time complexity analysis.
  • Write clean, readable code with comments explaining key parts of the solution.
Key Topics to Cover
Stacks
Token Validation
Algorithm Efficiency
Edge Cases
Code Readability
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you modify your solution to handle nested structures?
  • What would you do if the input stream was very large?
  • Can you explain the time and space complexity of your solution?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Approach

To validate a balanced INDENT and DEDENT token stream, we can use a stack data structure. The idea is to push an INDENT token onto the stack when encountered and pop from the stack when a DEDENT token...

Algorithm
  1. Initialize an empty stack.
  2. Iterate through each token in the stream:
    • If the token is INDENT, push it onto the stack.
    • If the token is DEDENT:
      • Check if the stack is empty. If it i...

Submit Your Answer
Markdown supported

Related Questions