← Questions

H-index of instance ratings

0
AmazonCodingLast asked Jan 2026

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.
  • k is at most the number of instances, and a rating equal to k counts toward k.

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) where ratings[i-1] >= i: O(n log n).
  • O(n) with counting: ratings above n go into bucket n, then a suffix sum from n down finds the first k whose count reaches k.
  • Equality at the threshold, ratings larger than n, zeros and negatives, and the empty array.
  • Binary search on k if 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

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