0

# Kth Percentile

Unsolved
###### Sorting

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

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

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

1- Sort the data from lowest to highest.

2- $i=\frac{k*n}{100}$     (n is the length of the vector of values)

$\frac{k*n}{100}" title="\frac{k*n}{100}" />$
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

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

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.

Input Test Case

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