Java Solution using Stack
\n    public String smallestSubsequence(String s) {\n        //character frequency\n        int[] count = new int[26];\n        for(char c : s.toCharArray()){\n
```\n    public String smallestSubsequence(String s) {\n        //character frequency\n        int[] count = new int[26];\n        for(char c : s.toCharArray()){\n            count[c-\'a\']++;\n        }\n        //to keep track of visited character so that we don\'t use them if present in answer\n        boolean[] visited = new boolean[26];\n        \n        //Stack store resulting characters\n        Stack<Character> stack = new Stack<>();\n        //traverse through string and add characters\n        for(char c : s.toCharArray()){\n            //dcrement the frequncy of character since we are using it in answer\n            //!!! We have decrement the character frequncy before checking it is visited\n            count[c - \'a\']--;\n            \n            //if already present in tstack we dont need the character\n            if(visited[c - \'a\']){\n                continue;\n            }\n            \n            //traverse through the stack and check for larger characters\n            //if found and it is not the last position then pop from stack\n            //Eg: bcabc => if stack has bc, now a<b and curr b is not the last one \n            //if not in last position come out of loop and add curr character to stack\n            while(!stack.isEmpty() && c < stack.peek() && count[stack.peek() - \'a\'] > 0){\n                //make the current character available for next operations\n                visited[stack.pop() - \'a\'] = false;\n            }\n            //add curr charatcer to string \n            stack.push(c);\n            //mark it as vistied\n            visited[c - \'a\'] = true;\n        }\n        \n        //Now characters are in reverse order in stack \n        //Use StringBuilder instead of String for storing result\n        StringBuilder sb = new StringBuilder();\n        while(!stack.isEmpty()){\n            sb.append(stack.pop());\n        }\n        \n        return sb.reverse().toString();\n        \n    }\n```
['Stack', 'Java']