Find the “Kth” max and min element of an array
One Subscription, For Everything
The new cool way of learning and upskilling -
One Subscription access everything
Get Access to PrepInsta Prime
from FAANG/IITs/TOP MNC's

PrepInstaPrime
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others.
Login/Signup to comment
#Find the “Kth” max and min element of an array
arr = [ 2 , 4 , 18 , 77 , 22 , -89 , 18 , 88 , 336]
low = 10**9
mx = -10**9
for i in range(len(arr)):
if arr[i] mx :
mx = arr[i]
print(f”Max element in Array : {mx}”)
print(f”min element in Array : {low}”)
k=int(input(‘enter k value’))
a=list(map(int,input().split()))
n=len(a)
def findkmax(k,a):
for i in range(n):
for j in range(0,n-1-i):
if a[j]a[j+1]:
a[j],a[j+1]=a[j+1],a[j]
print(a)
print(‘kin element’,a[k-1])
findkmax(k,a)
findkmin(k,a)
Hey there,
Thanks for commenting, Kindly join our Discord server, our mentors will guide you further with all your technical queries.
l=[10,56,20,48,21,458,-1,0,569]
n=len(l)
while True:
k=int(input(“Enter k: “))
if k<=n:
break
else:
print("Wrong value enter again: ")
l1=sorted(l)
min=l1[k-1]
max=l1[n-k]
print(min,max)
def minman(arr,k):
arr.sort()
max=arr[-k]
min=arr[k-1]
return min,max
arr=[1,25,38,43,54,68,72,28,19,12]
k=2
s,d=minman(arr,3)
print(s)
print(d)