0
How to find k^th smallest element from 1-D array.
6 Respuestas
+ 1
1. Sort the array in ascending order.
2. Remove duplicate values.
3. Get the k-th element from the array.
+ 1
Ipang , better:
2.
1.
3.
+ 1
Shadoff,
Isn't duplicate removal easier when the array is sorted?
+ 1
Ipang ,
l = [3,5,3,1,2,4,5]
l2 = list(set(l))
and then sorting and then getting k-th element
+ 1
Shadoff,
Yes that is the right way in Python. I guess things are different by language.
In C++ std::unique() works best with sorted collections.
So maybe implementation differ by language : )
+ 1
Thank you,
Guys.