Maximum Rating Threshold Count
Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Three ratings are at least 3, but only three are at least 4 fails, so the answer for [3,0,6,1,5] is 3. That's the whole game in the Amazon OA reported in October 2026: find the largest k where at least k entries are >= k. It's the h-index in disguise, and it looks harder than it is. If you blank on the trick, StealthCoder is the invisible safety net running on your desktop during the live assessment. But you can learn this one tonight.
The problem
Given a nonempty integer array ratings, return the largest integer k such that at least k entries in ratings are greater than or equal to k. Examples Example 1 ratings = [3,0,6,1,5] return = 3 Three ratings are at least 3: 3, 5, and 6. Four ratings are not at least 4, so the maximum threshold count is 3.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Sort the array descending. Walk through it with index i starting at 0. If ratings[i] >= i+1, then i+1 entries are at least i+1, so k = i+1 is valid. Stop at the first index where that fails, and return the last valid k. Sorting is O(n log n). You can hit O(n) with a counting array: cap every value at n, count occurrences, then scan k from n down to 0 while accumulating the suffix count until count >= k. The common pitfall is confusing the value with the count. The answer isn't a rating from the array, it's a threshold. Another trap is negative or zero values, so return 0 when nothing qualifies. Off-by-one errors on the index are the usual killer. If you freeze during the live OA, StealthCoder can hand you the working version fast.
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 Maximum Rating Threshold Count 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 h index. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Amazon's OA.
Amazon 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.
Maximum Rating Threshold Count FAQ
How hard is the Amazon Maximum Rating Threshold Count problem really?+
Easy to medium. It's the classic h-index problem. Once you see that the answer is a threshold and not an array element, it's about ten lines. Most people lose time on off-by-one errors, not on the idea.
What's the trick to solving it?+
Sort descending and find the last position i where ratings[i] >= i+1. That i+1 is your answer. The sorted order lets you reason about 'at least k entries' as simply the first k elements.
Can I do better than O(n log n)?+
Yes. Build a counting array of size n+1, clamping any rating above n to n. Then scan k from n down to 0, keeping a running total of counts. The first k where the total is >= k is the answer. That's O(n) time and space.
What edge cases should I test?+
Test all zeros (answer 0), all large values (answer is n), a single element, duplicates, and negatives if allowed. For [3,0,6,1,5] the answer is 3. Check that you return the threshold, not a value from the array.
How do I prepare for this in 48 hours?+
Write the sort version from memory, then the counting version. Run it on three or four small arrays by hand. Practice explaining why k=4 fails in the example. That covers this pattern and its common variants.