Cardinality Sort
Reported by candidates from Oracle's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Oracle's February OA threw Cardinality Sort at real candidates, and it's a sorting problem that looks straightforward until you realize the constraint. You're not sorting a normal array. The trick is understanding what "cardinality" means in this context and how to exploit it to beat the naive comparison-sort approach. This is a pattern-recognition problem wrapped in sorting language. StealthCoder can surface the key insight if you blank on the setup.
Pattern and pitfall
Cardinality Sort plays on the fact that when your data has limited range or unique values (low cardinality), you can sort without comparing elements head-to-head. The canonical move is counting sort or radix sort, which bucket elements by their value or digit. The trap is implementing a generic comparison sort and timing out. The real skill is recognizing when the input's cardinality makes linear-time sorting possible. On the live OA, you need to spot the constraint Oracle embedded in the problem statement (range of values, number of unique items, etc.) and pivot to the right algorithm. If you freeze, StealthCoder gives you the cardinality constraint and the sorting approach in real time.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Cardinality Sort 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. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Oracle's OA.
Oracle reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Cardinality Sort FAQ
Is this the same as counting sort or radix sort?+
Not exactly. Cardinality sort is a broader concept that includes counting and radix as special cases. The point is that low-cardinality data can be sorted faster than O(n log n). Oracle is testing whether you recognize the constraint and pick the right algorithm.
What's the main trick if I blank?+
Look for the cardinality constraint in the problem statement. It's usually a small range (e.g., values 1 to k, or k distinct elements). That's your signal to avoid comparison sorting. Bucket or count instead.
Can I just use the language's built-in sort?+
Maybe. If cardinality is very low, a built-in sort often passes. But Oracle's OA usually has tight time limits. The expected solution leverages the cardinality constraint explicitly. Don't rely on built-ins.
How long should I spend on this problem?+
If you recognize the pattern instantly, 10-15 minutes to code. If you don't, you'll spin on comparison sort and waste time. That's why the pattern matters. Know counting sort before the OA.
Is this still asked by Oracle in 2024?+
Yes. Reported in February 2024. Oracle likes sorting and constraint-recognition problems. Cardinality Sort is a reliable signal of their focus on efficient algorithms under special conditions.