Reported March 2025
Pure Storagehash table

Bakery Quality Control

Reported by candidates from Pure Storage's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Pure Storage OA. Under 2s to a working solution.
Founder's read

The Pure Storage OA reported in March 2025 looks like a warm-up, and that's the trap. Bakery Quality Control hands you pairs of strings and asks how many boxes don't match their template. Order doesn't matter, but counts do. Most people see "compare two strings" and write something that passes the sample and dies on a hidden case. This is a multiset comparison, nothing fancier. If you blank under the timer, StealthCoder runs invisibly on the live OA and gives you the solution so one silly bug doesn't cost you the round.

The problem

Your program controls boxes of pastries coming out of a bakery. For each produced box, you are required to compare its contents to a list of expected items (its "template") and determine whether the box is correct or not. The contents of a box is described by a string such as "pcm" for 'p'ie, 'c'ookie, and 'm'uffin, or "ddp" for 'd'onut, 'd'onut, and 'p'ie. The template is described in the same manner. So given a list of (box, template) pairs, your program should indicate how many times it found a mismatch between a box and its template and return that total.
A box contains no more than 10 items, and there are no more than 1000 boxes to check at a time. Items in a box can be repeated, so "cc" (cookie cookie) is not the same as "c" (cookie). Items are not ordered, so the box "cm" (cookie, muffin) matches the template "mc" (muffin, cookie).

Function
countMismatchedBoxes(boxes: String[][]) → int
Complete the function countMismatchedBoxes in the editor.
countMismatchedBoxes has the following parameters:
String[][] boxes: a list of pairs where each pair contains the contents of a box followed by its expected template
Returns
int: the number of boxes that do not match their templates

Examples
Example 1
boxes = [["cm", "mc"], ["ccm", "mc"], ["pm", "mc"], ["c", "mc"]]
return = 3
The pair ["cm", "mc"] is valid; the order of items in the box doesn't matter.
The pair ["ccm", "mc"] is invalid; there are too many cookies in the box.
The pair ["pm", "mc"] is invalid; there is a pie in the box, and no cookie.
The pair ["c", "mc"] is invalid; there is a muffin missing in the box.
Given that list, your program should return 3, as it found 3 invalid boxes out of 4.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is that a box matches its template only if both strings contain the same items with the same frequencies. Two clean ways to do it: sort both strings and compare them, or count characters in a 26-slot array or hash map and compare the counts. With at most 10 items per box and 1000 boxes, either is trivially fast. The edge case that breaks the naive version is using a set comparison or a contains check. "ccm" against "mc" passes a set check because the sets are equal, but it's wrong because there are too many cookies. Length-only checks fail too, since "pm" and "mc" are the same length. Compare full frequencies, count the mismatches, return the total. If you freeze mid-assessment, StealthCoder is the hedge that reads the prompt and hands you the counting approach so you can submit clean.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Bakery Quality Control cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Pure Storage's OA.

Pure Storage reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Bakery Quality Control FAQ

How hard is Bakery Quality Control really?+

It's easy. It's an anagram check run over a list of pairs. The difficulty is only in not oversimplifying it. If you handle repeated items correctly, you've solved the core of it, and the loop around it is just a counter.

What's the trick to this Pure Storage question?+

Compare frequencies, not sets. "ccm" versus "mc" has identical sets but different counts, so it's a mismatch. Sorting both strings and comparing them, or building a character count, handles duplicates and ignores order in one move.

Should I sort or use a hash map?+

Either passes. Sorting is shorter to write: sort both strings and compare. A count array is slightly faster and just as simple. With 10 items per box and 1000 boxes, performance isn't a concern, so pick whichever you can write without bugs.

What edge cases should I test before submitting?+

Test repeated items like "cc" versus "c", same length but different items like "pm" versus "mc", and order differences like "cm" versus "mc". Also check that you return the number of mismatches, not matches. The sample answer of 3 out of 4 is a good sanity check.

How do I prepare for this in 48 hours?+

Practice the anagram pattern until you can write it from memory in both sorting and counting forms. Then practice reading the return value carefully. Here the function returns invalid boxes, and flipping that is the most common avoidable error.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Pure Storage.

OA at Pure Storage?
Invisible during screen share
Get it