0

Kth Percentile

Unsolved
Fundamentals
Prob. and Stats
Sorting

Difficulty: 4 | Problem written by zeyad_omar
Problem reported in interviews at

Amazon
Apple
Facebook
Google
Netflix

Finding the kth percentile is very important in data science and data analysis and has many applications. For example, assume you have a test in your school and the top 10 out of 100 students will get a reward. Let's say you got a score of 85%. Can you tell if you are going to get the reward or not? The answer is NO you can not. But now, let's say you know that you have scored higher than 99 students. Then now you know...and congratulations smiley

In this problem you are required to write a function that calculates the kth percentile given K and a 1D vector of values.

You can follow this algorithm:


1- Sort the data from lowest to highest.


2-      (n is the length of the vector of values)


3a - If i is an integer, then return value at index i.

3b - Else, then round i down and round i up then return the average of those two values.

3.c - Return -1 if the kth percentile is not in the list.

Sample Input:
<class 'list'>
values: [1, 2, 3, 4, 5]
<class 'int'>
k: 20

Expected Output:
<class 'int'>
2

This is a premium problem, to view more details of this problem please sign up for MLPro Premium. MLPro premium offers access to actual machine learning and data science interview questions and coding challenges commonly asked at tech companies all over the world

MLPro Premium also allows you to access all our high quality MCQs which are not available on the free tier.

Not able to solve a problem? MLPro premium brings you access to solutions for all problems available on MLPro

Get access to Premium only exclusive educational content available to only Premium users.

Have an issue, the MLPro support team is available 24X7 to Premium users.

This is a premium feature.
To access this and other such features, click on upgrade below.

Log in to post a comment

Comments
Ready.

Input Test Case

Please enter only one test case at a time
numpy has been already imported as np (import numpy as np)