Maximum Rating Threshold Count
Updated
Problem statement
You are given a non-empty integer array ratings. Find the largest integer k where at least k of the entries in ratings are greater than or equal to k. Return that k.
The entries you count can be anywhere in the array. They do not have to sit next to each other. If no positive value of k works, return 0.
Function
maximumRatingThreshold(ratings: int[]) → intExamples
Example 1
ratings = [3,0,6,1,5]return = 3Three ratings are at least 3: 3, 5, and 6. For k to be four, you would need four ratings that are at least 4, but only two are. So the answer is 3.
Example 2
ratings = [1,1,1]return = 1All three ratings are at least 1, so k can be one. No rating is at least 2, so k cannot be two or more. The answer is one.
Example 3
ratings = [0,0,0,0]return = 0No rating is at least 1, so no positive k works. The answer is zero.
Constraints
1 <= ratings.length <= 200000.0 <= ratings[i] <= 10^9.
More Amazon Online Assessment questions
- Lexicographically Largest IdentifierOA · Seen Nov 2026
- Maximize Shipment Order by Sorting One WindowOA · Seen Nov 2026
- Top K Frequent ElementsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Fill One Exact-Length Binary WindowOA · Seen Nov 2026
- Minimum Grid InconvenienceOA · Seen Nov 2026
- Maximize K-Element AND with an Increment BudgetOA · Seen Nov 2026
- Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Get Smallest Base SegmentOA · Seen Nov 2026
- Minimum Cost of Left and Right PropagationOA · Seen Nov 2026
- Maximum Equal-Bit Pairs in a SubsequenceOA · Seen Nov 2026
Similar questions at other companies
- Count Lamps Lighting Each PointAirbnb · OAAirbnb interview questions
- Merge IntervalsApple · OA · PHONE SCREEN · ONSITE INTERVIEWApple interview questions
- Earliest Meeting Time for All EmployeesCapital One · OACapital One interview questions
- Capping Portfolio WeightsCapstone Investment Advisors · OA
- Count Servers With No Requests in a Time WindowIBM · OAIBM interview questions
- Maximum Escape Game ScoreMicrosoft · OAMicrosoft interview questions
- Largest Team Where Every Pair OverlapsWalmart · OAWalmart interview questions
- Maximum Distinct Values After Unit AdjustmentsBirla Pivot · OA
- Minimum Meeting RoomsJP Morgan Chase · OAJP Morgan Chase interview questions
- Minimize Task Resource ConsumptionNVIDIA · OANVIDIA interview questions