I have a string input by the user and an integer k. How do I get the lexicographically kth smallest character from the input string?
Here is what I have been trying
static Character find(int K, String s){
SortedSet<Character> ss = new TreeSet<Character>();
for(Character c : s.toCharArray()){
ss.add(c);
}
Iterator it = ss.iterator();
int i=0;
while (it.hasNext()) {
Object element = it.next();
if(i==K-1)
return (Character) element;
}
return null;
}