Count Total Picks in a Nested Kitting Bundle Formula

Last updated: November 29, 2026

Quick Overview

Bundle SKUs are described by formulas where an item name starts with an uppercase letter followed by lowercase letters, an optional count follows, and parentheses group items with an optional multiplier, e.g. `Kit(Pen2Cap)3Tape`. Return each item's total count as a string in sorted name order like `Cap3Kit1Pen6Tape1`.

Amazon
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Hard

0

0

0 solved


Bundle SKUs are described by formulas where an item name starts with an uppercase letter followed by lowercase letters, an optional count follows, and parentheses group items with an optional multiplier, e.g. `Kit(Pen2Cap)3Tape`. Return each item's total count as a string in sorted name order like `Cap3Kit1Pen6Tape1`.

A harder online assessment style problem in Amazon's style, framed around kitting and bundle definitions in fulfillment, where a bundle must be expanded into picks. It checks a stack of count maps, careful tokenizing of names and numbers, and correct propagation of multipliers through nested groups.

What the Interviewer Expects
  • Tokenizes names (uppercase plus lowercase run) and multi-digit counts
  • Uses a stack of counters, one per open parenthesis
  • Applies the group multiplier when popping
  • Treats a missing count as 1
  • Formats output in sorted order, omitting count 1 only if specified
Key Topics to Cover
string parsing
stack
hash maps
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 detect and report unbalanced parentheses?
  • How would you handle bundles that reference other named bundles, possibly recursively?
  • Can counts overflow in a typed language, and how would you guard against it?
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: Name := [A-Z][a-z]*, Count := [0-9]* (empty means 1), Group := '(' Formula ')' Count. Output concatenates name + count in sorted name order, always writing the count. Confirm whether ...

High-Level Design

Maintain a stack of counters. The bottom counter is the final answer. On (, push a fresh counter. On a name, read its optional count and add to the top counter. On ), read the multiplier that foll...


Submit Your Answer
Markdown supported