1

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]
k: 20

Expected Output:
<class 'int'>
2

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Iure perspiciatis expedita ratione sequi dolor laborum deleniti officiis ducimus dicta, dignissimos asperiores accusamus.

Fugiat ipsa temporibus doloribus vel dignissimos perferendis ducimus pariatur provident ad, neque alias earum cum in incidunt velit tempora eaque? Alias nemo in ut praesentium, amet praesentium rem qui harum, vitae reprehenderit temporibus consequuntur velit deserunt aliquid rerum, omnis quo totam mollitia nulla aperiam nesciunt eos corrupti vel, officiis expedita dolore odio nam excepturi illo nulla nisi. Dolore repudiandae perferendis numquam iste vel repellendus itaque nostrum est dignissimos suscipit. Vitae eum quisquam excepturi reiciendis nobis ipsum nesciunt impedit, tempore odit eum impedit placeat corporis maxime est necessitatibus voluptas, tempora libero nam aut perferendis, dolor temporibus qui asperiores delectus suscipit nulla ipsam.

Sint velit quam aperiam vero dolore distinctio, eos aliquam officiis deleniti necessitatibus ut deserunt sed quasi voluptatum itaque quia.

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

Ready.

Input Test Case

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