Maybe I am not using the right data structure. I need to use a set, but also want to efficiently return the k-th smallest element. Can TreeSet in Java do this?
TreeSet
TreeSet a=new TreeSet<>(); a.add(1); a.add(2); a.add(-1); System.out.println(a.toArray()[0]);
it can be helpfull