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
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.