← Questions
H-index of instance ratings
0
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Amazon's online assessment, last asked Jan 2026. It tests sorting, counting and binary-search.
Given the integer ratings of a set of instances, return the largest integer k such that at least k instances have a rating of k or more. Return 0 when no positive k qualifies.
Interface
Unless you agree on a different interface with the interviewer, assume:
max_threshold(ratings: list[int]) -> int
Example
max_threshold([3, 0, 6, 1, 5]) -> 3 # 3, 6 and 5 are >= 3; only two ratings are >= 4
max_threshold([4, 4, 4, 4, 4]) -> 4 # k cannot exceed the number of instances
max_threshold([1, 1, 1]) -> 1
max_threshold([0, 0]) -> 0
max_threshold([]) -> 0
Constraints
- The array may be empty; ratings are integers and may be 0 or negative.
-
kis at most the number of instances, and a rating equal tokcounts towardk.
Clarifying questions
- Can ratings be negative, and how large can they get?
- What should an empty array return?
- Is the array already sorted?
What a strong answer covers
- Sort descending and find the last position
i(1-based) whereratings[i-1] >= i: O(n log n). - O(n) with counting: ratings above
ngo into bucketn, then a suffix sum fromndown finds the firstkwhose count reachesk. - Equality at the threshold, ratings larger than
n, zeros and negatives, and the empty array. - Binary search on
kif the array is sorted, in O(log n).
Follow-ups
- Ratings arrive one at a time. Keep the answer current after each.
- The ratings are sorted ascending. Answer in O(log n).
Where it's asked
- Amazon · Online assessment · Last asked Jan 2026Coding problems plus a repository bug-fix section with a built-in assistant or a design scenario, then a work-style survey · AI only inside the bug-fix section's built-in assistant
What it tests
sorting · counting · binary-search
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding
