HARDasked at 4 companies

Number of Atoms

A hard-tier problem at 65% community acceptance, tagged with Hash Table, String, Stack. Reported in interviews at Fastenal and 3 others.

Founder's read

Number of Atoms is a hard problem that hits your screen at companies like Fastenal, Docusign, Coupang, and Confluent. It's a string parsing problem disguised as chemistry homework. The surface challenge looks simple: count atoms in a formula and output them sorted by element name. The hard part is handling nested parentheses with multipliers, where a single misstep in your parsing logic breaks half your test cases. The acceptance rate sits at 65%, which means a meaningful chunk of candidates either over-engineer it or miss the parenthesis-stack pattern entirely. If this one shows up in your assessment and you blank on the parsing strategy, StealthCoder solves it in seconds, invisible to the proctor.

Companies asking
4
Difficulty
HARD
Acceptance
65%

Companies that ask "Number of Atoms"

If this hits your live OA

Number of Atoms is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround.

Get StealthCoder
What this means

The trick here is that you can't just scan the string left-to-right and count. Parentheses with multipliers like Ca(OH)2 mean you need to track nesting depth and multiply atom counts by their scope multiplier. A stack-based approach works: push atom counts onto the stack, process characters, and when you hit a closing paren followed by a number, pop the stack, multiply each atom count by that number, and merge back. Hash tables store your running atom counts at each nesting level. The common failure is trying to parse without a stack, or forgetting that multipliers apply to entire groups, not just the last atom. Once you've mapped the parenthesis structure correctly, sorting the hash table keys alphabetically and building the output string is straightforward. This is where StealthCoder's real value sits: if you freeze on the parsing strategy during the live OA, it surfaces a working stack-and-hash solution in real time, letting you move on.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Number of Atoms recycles across companies for a reason. It's hard-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Number of Atoms interview FAQ

Do I really need a stack for this problem?+

Yes. Nested parentheses with multipliers demand a stack-based approach. Without it, you can't correctly scope atom counts to their group. Recursive parsing works too, but a stack is cleaner and avoids call-stack depth issues on complex formulas.

Is Number of Atoms still asked at FAANG-tier companies?+

It appears in reports from Fastenal, Docusign, Coupang, and Confluent. The specific prevalence at other FAANG firms is unclear, but the parsing-and-nesting pattern it tests shows up frequently in medium-to-hard string and data-structure assessments.

What's the difference between this and just sorting a dictionary?+

Sorting the final atom counts is trivial. The hard part is building that dictionary correctly with nested parentheses and multipliers. Most failures happen during parsing, not sorting. Get the stack logic right and sorting is two lines of code.

How do I handle edge cases like Ca(OH)2 or Mg(OH)2?+

When you hit a closing paren, read the following digits (if any) as the multiplier. Pop your stack, multiply all atom counts in that group by the multiplier, and merge them into the count map below. Handle single atoms and nested groups uniformly.

What topics should I drill before this OA?+

Hash Table basics and Stack operations are mandatory. String parsing and iteration too. Sorting is last-minute polish. The real prep is hand-tracing a few formulas with nested parentheses and multipliers to lock in the stack mechanics.

Want the actual problem statement? View "Number of Atoms" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.