"Farway Home" is an online platform where users can buy property. This platform has a list of N plots numbered 0 to (N-1). The list consist of the specified area for each plot. The platform provides an application where a user can identify the plots with the Kth largest area from the list.
Write an algorithm to find the plot with the Kth largest area.
Input The first line of the input consists of an integer-size, representing the number of plats (N). The second line consists of N space separated integers-areas0, area1 ...... areaN-1, representing the areas of the plots.
The last line consists of an integer value, representing the value for which the user wishes to find the area (K).


Output

Print an integer representing the plot

with the Kth largest area.

Example:

Input

7

10 5 7 88 19 45 56

3

Output

45

Explanation: 

The sorted areas are [88,56,45,19, 10, 7, 5]. So, the 3rd largest area is 45.

 

Solutions:

arr=[]
n=int(input())
x=input()
k=int(input())
arr2=x.split()
for i in range(n):
    arr.append(int(arr2[i]))
arr.sort(reverse=True)
print(arr[k-1])
 



Share to whatsapp

More Questions from Entrance Exam Questions Module 1

"Farway Home" is an online platform where users can buy property. This platform has a list of N plots numbered 0 to (N-1). The list consist of the specified area for each plot. The platform provides an application where a user can identify the plots with the Kth largest area from the list.
Write an algorithm to find the plot with the Kth largest area.
Input The first line of the input consists of an integer-size, representing the number of plats (N). The second line consists of N space separated integers-areas0, area1 ...... areaN-1, representing the areas of the plots.
The last line consists of an integer value, representing the value for which the user wishes to find the area (K).
View
Primes with a Twist
Given an integer n(1<=n<=10^4), you need to count the numbers, x,< n, which are co-prime to 'n', i.e. gcd(x,n)=1.
Formally, given n, you need to find f(n)=[{x<n:gcd(x,n)=1}].
Return the count of the number of co-primes of 'n'.
View
Write a program that will take one string as input. The program will then remove vowels a, e, i, o, u from the string. If there are two or more than two vowels that occur together then the program shall ignore all of those vowels.
View