+ 1

# How to find the nth minimum number in array?

So here I am trying to implement it in a easy way ,rather than the other solutions I came across like sorting it ,so I wanna know is my solution right for nth minimum number? Like if minimum number is 2 in the following array next minimum will be 3 ,and if 3 is minimum number ,next one will be 4,thks in advance! Edit: also in this approach I need to find maximum number first which is 8 here https://code.sololearn.com/cO1PsQIKsUpE/?ref=app

17th Oct 2020, 12:56 PM
Abhay
+ 2
a = [8,80,543,89,965332,57,9,6,4,3,6,9,0,7,5,5,8,] #print(f"{min(a)} is smallest") var_len = len(a) fl = [] for loop in range(var_len) : for i in a: lst = [] for k in a: if k<i: lst.append(1) else : lst.append(0) if 1 not in lst: fl.append(str(i)) a.remove(i) print(" < ".join(fl)) See this logic I simply built up instead of sort method. This will give you a sorted list. Or else simply use sort function and find nth minimum numbers
17th Oct 2020, 1:01 PM

+ 2
Use vector Stl library sort elements and you can make your code in less lines . read this post it will help you https://www.geeksforgeeks.org/find-maximum-and-minimum-element-in-a-set-in-c-stl/
17th Oct 2020, 5:16 PM
ASR
+ 1
♨️TEJAS MK-82♨️ as I already mentioned I can use that sort from stl but i don't wanna ,it comes with some overhead as well ,might be expensive and wondering if they really allow using that sort method in interviews?
17th Oct 2020, 6:36 PM
Abhay
0

17th Oct 2020, 1:03 PM
Abhay