Count Color Pairs
Reported by candidates from Instacart's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Instacart's March 2025 OA threw this at candidates: Count Color Pairs. No problem text leaked, but the title tells you everything. You're counting pairs of colors, which means you're either iterating through a list, using a hash table to track frequencies, or spotting a mathematical pattern in how pairs combine. The trick isn't usually the counting itself. It's understanding what "pair" means in this context, and whether order matters. StealthCoder reads the exact problem on your screen and surfaces the pattern instantly if your mind goes blank under pressure.
Pattern and pitfall
A color-pair counting problem almost always reduces to one of three approaches: brute force iteration (O(n^2), rarely the answer), hash-table frequency mapping (O(n) with O(n) space), or a mathematical formula if there's a closed-form solution. The common pitfall is miscounting duplicates or misunderstanding whether (red, blue) and (blue, red) are the same pair. Most candidates overcomplicate it by trying to generate all pairs when a frequency count or combinatorial formula does the work. In the live OA, if you freeze on the definition of "pair," StealthCoder unblocks you by showing the exact problem statement and letting you think clearly for 30 seconds before committing code.
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 Count Color Pairs 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
This OA pattern shows up on LeetCode as number of 1 bits. If you have time before the OA, drill that.
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.
Count Color Pairs FAQ
Is this a hash-table problem or a math problem?+
Both can work, depending on the input. If you're counting pairs of distinct colors in a list, hash-table frequency mapping is safer and more generalizable. If the problem hints at a formula (e.g., n * (n - 1) / 2 for all possible pairs), go mathematical. Read the exact wording on screen before committing.
Does order matter: is (red, blue) different from (blue, red)?+
This is the crux. If the problem says "unordered pairs," divide by 2 or use a set to avoid duplicates. If it says "ordered pairs" or lists them as position-based, count both. The problem text will make this explicit. Don't guess.
What if there are duplicate colors in the input?+
If you have three reds, you can form three choose two = 3 pairs of reds. Use a frequency map to count how many times each color appears, then apply the combinatorial formula C(count, 2) to each color. Sum the results.
How do I prepare for this in 48 hours?+
Understand hash-table counting (very fast, 10 minutes). Know the combination formula n * (n - 1) / 2. Practice one easy pair-counting problem (LeetCode 1512 or 2815). Then stop. You don't need more.
What's the real catch Instacart is testing?+
Clarity under vague requirements. The title doesn't say what a "pair" is. Instacart wants to see if you ask questions or make assumptions. In the live OA, read the problem three times before you code. Your first instinct is usually correct.