Find the Largest Rating Threshold Supported by K Instances
AmazonSoftware Engineer · Online AssessmentLast updated
Find the largest k for which at least k instance ratings are at least k, handling threshold equality and the zero-answer case.
Given an array of integer instance ratings, return the largest integer k such that at least k instances have ratings greater than or equal to k.
Input and Output
- Input: an array of integer ratings, one value per instance.
- Output: one integer, the maximum qualifying
k. Return0when no positivekqualifies. kcannot exceed the number of instances. A rating equal tokmeets the threshold.- For this practice version, an empty array has answer
0.
Example 1
ratings = [3, 0, 6, 1, 5]
answer = 3
Three ratings are at least 3: 3, 6, and 5.
Example 2
ratings = [0, 0]
answer = 0
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.