Expand Nested Repeat Markers in Compressed Danmaku Text

Last updated: November 29, 2026

Quick Overview

Bullet comments arrive compressed so that k[text] means text repeated k times, with nesting allowed (for example 2[b2[c]]). Return the fully expanded string.

ByteDance
Coding & Algorithms
Software Engineer
ByteDance
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Bullet comments arrive compressed so that k[text] means text repeated k times, with nesting allowed (for example 2[b2[c]]). Return the fully expanded string.

Danmaku (scrolling bullet comments) on Douyin and Xigua Video can be spammy and repetitive, so a compact encoding saves bandwidth for repeated emoji and laughter. The interviewer uses this to see whether you reach for a stack when nesting appears, and whether you handle multi-digit counts without fuss.

What the Interviewer Expects
  • Recognize nested structure and use an explicit stack or recursion
  • Accumulate multi-digit repeat counts correctly
  • Avoid quadratic string concatenation by building lists
  • State output-size complexity, not just input size
  • Discuss a guard against expansion bombs
Key Topics to Cover
stack
string parsing
recursion
nested structures
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 cap output size to protect the client from a malicious 999[999[x]] payload?
  • Write the recursive version and compare stack depth risks.
  • How would you produce the encoding in the first place for a given repetitive string?
Sharpen Your Skills on Codemia

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

Practice DSA Problems
Sample Answer
Requirements

Input contains lowercase letters, digits, and balanced brackets. A number always precedes [. Counts can have several digits. Text outside brackets is copied as is. Assume the encoding is well formed...

High-Level Design

Scan left to right while keeping the text built at the current nesting level and the number being read. On [, push the text so far and the count onto a stack, then start a fresh level. On ], pop t...


Submit Your Answer
Markdown supported