Nearest-Rank Percentile Without Sorting
Updated
Problem statement
Given a nonempty integer array values and an integer percentile p from 1 through 100, return the nearest-rank percentile.
Its one-based rank is ceil(p * values.length / 100). Return the value at that rank in sorted order, but do not sort the complete array. You may rearrange values.
Function
nearestRankPercentile(values: int[], p: int) → intExamples
Example 1
values = [7,1,3,9,5]p = 50return = 5The nearest rank is ceil(50 * 5 / 100) = 3; the third sorted value is 5.
Example 2
values = [10,20,30,40]p = 75return = 30The nearest rank is 3, so the answer is 30.
Constraints
1 <= values.length <= 200000-10^9 <= values[i] <= 10^91 <= p <= 100
More Microsoft Onsite Interview questions
- Bad Request AlertsONSITE INTERVIEW · Seen Nov 2026
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
- Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
- Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
- Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
- Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
- Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
- Coin ChangeONSITE INTERVIEW · Seen Oct 2026
- Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
- Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Top Ten Largest FilesGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Valid Triangle NumberBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Travelers per Consecutive City TripletUber · ONSITE INTERVIEWUber interview questions
- Merge Overlapping IntervalsShnoor International · ONSITE INTERVIEW
- Generate All Permutations of a NumberFleetx · ONSITE INTERVIEW
- Rank Word-Translation Hints from Sentence TranslationsDuolingo · PHONE SCREEN · ONSITE INTERVIEWDuolingo interview questions
- Top K Frequent ElementsAmazon · OA · PHONE SCREEN · ONSITE INTERVIEW
- Fair Capped Money DistributionGusto · PHONE SCREEN · ONSITE INTERVIEWGusto interview questions
- Group AnagramsAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
- Merge IntervalsApple · OA · PHONE SCREEN · ONSITE INTERVIEWApple interview questions