FastPrepNearest-Rank Percentile Without Sorting
Problems/Nearest-Rank Percentile Without Sorting

Nearest-Rank Percentile Without Sorting

Microsoft logoMicrosoft● MediumNEW GRADONSITE INTERVIEW

Updated Oct 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A Microsoft Data Scientist internship report asks for the Nth percentile and follows up with an input too large to sort fully. The nearest-rank convention, in-memory selection model, in-place rearrangement, percentile range, and bounds are conventional enrichment.

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) → int

Examples

Example 1

values = [7,1,3,9,5]p = 50return = 5

The nearest rank is ceil(50 * 5 / 100) = 3; the third sorted value is 5.

Example 2

values = [10,20,30,40]p = 75return = 30

The nearest rank is 3, so the answer is 30.

Constraints

  • 1 <= values.length <= 200000
  • -10^9 <= values[i] <= 10^9
  • 1 <= 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

Interview reports that mention this question

  • Microsoft AI/ML Intern Interviews: 114 Experiences (Part 1 of 2)

Microsoft interview experiences

  • Microsoft OA Questions, October 2026: 4 Experiences
  • Microsoft Experienced SWE Phone Screen: 1 Experience
  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public int nearestRankPercentile(int[] values, int p) {
      // Write your code here.
    }

}
Checking account…