Java greedy solution
We use greedy method here, first iterate all the characters in text, if we find the current one is smaller than already added ones, the push the current in the 
We use greedy method here, first iterate all the characters in text, if we find the current one is smaller than already added ones, the push the current in the front and pop back the already added\n```\n public String smallestSubsequence(String text) {\n\t\t int[] count = new int[26];\n\t\t for(int i=0;i<text.length();i++) {\n\t\t\t char c = text.charAt(i);\n\t\t\t count[c-\'a\']++;\n\t\t }\n\t\t \n\t\t boolean[] used = new boolean[26];\n\t\t Arrays.fill(used,false);\n\t\t StringBuilder sb = new StringBuilder();\n\t\t for(int i=0;i<text.length();i++) {\n\t\t\t char c = text.charAt(i);\n\t\t\t if(used[c-\'a\']) {\n\t\t\t\t count[c-\'a\']--;\n\t\t\t\t continue;\n\t\t\t }\n\t\t\t int last = sb.length()-1;\n\t\t\t while(sb.length()>0 && c<sb.charAt(last) && count[sb.charAt(last)-\'a\']>0) {\n\t\t\t\t used[sb.charAt(last)-\'a\'] = false;\n\t\t\t\t sb.deleteCharAt(last);\n\t\t\t\t last-=1;\n\t\t\t }\n\t\t\t used[c-\'a\'] = true;\n\t\t\t sb.append(c);\n\t\t\t count[c-\'a\']--;\n\t\t }\n\t\t \n\t\t \n\t\t return sb.toString();\n\t\t\n\t }\n\t\n```
[]