"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])