Expand Compressed Bulk SKU Codes Like 2[AB3[C]]

Last updated: November 29, 2026

Quick Overview

Warehouse bulk manifests encode repeated SKU fragments as k[fragment], possibly nested. Given an encoded string, return the fully expanded string.

Flipkart
Coding & Algorithms
Software Engineer
Flipkart
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Medium

0

0

0 solved


Warehouse bulk manifests encode repeated SKU fragments as k[fragment], possibly nested. Given an encoded string, return the fully expanded string.

Used in Flipkart phone screens to test string parsing with nested structure, phrased around compact manifests sent between warehouse systems. The interviewer checks stack based parsing, multi digit counts, and clean handling of nesting.

What the Interviewer Expects
  • Handle multi digit repeat counts
  • Use a stack of (previous string, count) frames for nesting
  • Build strings with lists to avoid quadratic concatenation
  • Explain behavior on plain text without brackets
  • Discuss output size versus input size
Key Topics to Cover
string parsing
stack
nested structures
recursion
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 validate malformed input like unbalanced brackets?
  • What if the expanded output could be gigabytes, and you only need the character at index i?
  • How would you write the inverse (compress a 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
  • Grammar: text is letters, or k[text] where k is a positive integer, nested arbitrarily.
  • Output: the expanded string.
  • Assume valid input for the core solution; validation is a follow up....
High-Level Design

Scan left to right, keeping the fragment being built (parts) and the number being read (num). On [, push the current fragment and count onto a stack and start fresh. On ], pop the frame, repea...


Submit Your Answer
Markdown supported

Related Questions