Sort Products by Aisle With Frozen Items Last
Reported by candidates from Instacart's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Instacart reported this one in September 2026, and it looks like a freebie. Sort grocery records by frozen flag, aisle descending, then SKU ascending. Pattern is sorting with a custom comparator. The trap isn't the algorithm, it's the parsing and the comparator details. Aisle can be negative, SKUs are strings, and 10^5 records means you can't be sloppy. If you blank on the comparator during the live OA, StealthCoder is the invisible safety net that reads the problem and hands you a clean solution. Otherwise, here's the script.
The problem
Each product record has the form sku|name|quantity|priceCents|aisle|isFrozen. Return the product SKUs in this deterministic order: All non-frozen products before all frozen products. Within each group, aisle number descending. Within the same group and aisle, SKU lexicographically ascending. The other product fields do not affect ordering. Function sortProductSkus(products: String[]) → String[] Examples Example 1 products = ["A7|Apple|1|100|7|false","A2|Bread|1|200|2|false","F100|Ice|1|300|100|true","F3|Peas|1|400|3|true"] return = ["A7","A2","F100","F3"] Both non-frozen records come first with aisle 7 before aisle 2. Frozen aisle 100 still follows every non-frozen item. Example 2 products = ["B|B|1|1|5|false","A|A|1|1|5|false","D|D|1|1|8|true","C|C|1|1|8|true"] return = ["A","B","C","D"] Each pair shares its group and aisle, so SKU order breaks both ties. Example 3 products = ["Z|Z|1|1|-2|true","X|X|1|1|0|false","Y|Y|1|1|-5|false"] return = ["X","Y","Z"] Descending aisle order places non-frozen aisle 0 before -5; the frozen record remains last. Constraints 1 <= products.length <= 10^5. Every record is syntactically valid and contains a unique non-empty SKU. String fields do not contain |. aisle is a signed 32-bit integer, and isFrozen is true or false.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Split each record on the pipe, pull out sku, aisle and isFrozen, then sort with a three-key comparator: frozen false before true, aisle descending, SKU ascending. The edge case that breaks naive solutions is comparing aisle as a string. Then "100" sorts before "7" and negatives go haywire. Parse aisle as an integer, and use a comparison that can't overflow, so don't subtract two 32-bit values. Compare SKUs as plain strings, lexicographically, not numerically, so "F100" comes before "F3". Example 1 shows exactly that. Also don't sort by name, quantity or price, they're noise. Complexity is O(n log n) with n up to 10^5, which is fine. Parse once into tuples instead of re-splitting inside the comparator. If your mind goes blank mid-assessment, StealthCoder runs invisibly and gives you the comparator in real time.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Sort Products by Aisle With Frozen Items Last 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 by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Instacart's OA.
Instacart reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Sort Products by Aisle With Frozen Items Last FAQ
How hard is this Instacart OA question really?+
Easy on algorithm, tricky on details. It's a multi-key sort. Most failures come from string-comparing the aisle, subtracting integers in a comparator and overflowing, or mishandling negative aisles. If you write the comparator carefully, it's a few minutes of work.
What's the trick to getting it right?+
Parse aisle to an integer and build a key of frozen flag, negative aisle, SKU. Sorting ascending on that key gives frozen last, aisle descending, SKU ascending. Be careful negating the minimum 32-bit value in a language with fixed ints. Use a wider type or an explicit comparator.
Should SKUs be compared numerically or lexicographically?+
Lexicographically, as plain strings. Example 1 proves it: F100 comes before F3 because the character 1 is less than 3. Don't strip prefixes or parse numbers out of the SKU. Uniqueness is guaranteed, so ties never go past SKU.
Is sorting still a common OA pattern?+
Yes. Custom comparator sorts on parsed records show up constantly because they test attention to detail more than algorithms. Expect string parsing, multiple tie-breakers and signed values. The Instacart report from September 2026 fits that mold.
How do I prepare for this in 48 hours?+
Write a multi-key sort in your language of choice three times, with a descending key and a string key. Test with negative numbers and mixed-length SKUs. Practice splitting on a pipe character, since in some languages it needs escaping in regex-based split functions.