Find the kth maximum and minimum



Problem to find the kth maximum and minimum number in the given list.



Example-1:


Input    : n = [ 17, 5, 9, 19, 2, 25, 3]  k = 3
Output   : 5 17 
Explain  : k th minimum = 5 and k th maximum = 17.  


Example-2:


Input    : n = [ 17, 5, 9, 19, 2, 25, 3]  k = 2
Output   : 3 19
Explain  : k th minimum = 3 and k th maximum = 19.  







Solution




n = [ 17, 5, 9, 19, 2, 25, 3]

k = 3

a = sorted(n)

b = a[k-1]

c = a[-k]

print(b,c)



Output



5 17