Java solution using stack with explanation
Use a stack to maintain a running sequence of smallest subsequence. \n2. Iterate over the test string and check in the queue 1. if the character is visites befo
1. Use a stack to maintain a running sequence of smallest subsequence. \n2. Iterate over the test string and check in the queue 1. if the character is visites before 2. if the character is smaller than the head of the queue 3. if the head of the queue is has more occurence later.\n3. if all the above condition we remove the head and we continue doing this untill queue is empty or head dont satisfy this condtion.\n\n\n```\nclass Solution {\n    public String smallestSubsequence(String text) {\n                Deque<Character> s = new LinkedList<Character>();\n\n\n                int[] count = new int[26];\n\n                for(int i=0;i<text.length();i++){\n                        count[text.charAt(i)-97]++;\n                }\n\n                boolean[] visited = new boolean[26];\n\n                for(int i=0;i<text.length();i++){\n\n                        char c = text.charAt(i);\n\n                        if(!visited[c-97]){\n                                while(!s.isEmpty() && s.peek() > c && count[s.peek()-97] > 0){\n                                        visited[s.peek()-97] = false;\n                                        s.pop();\n                                }\n\n                                s.push(c);\n                                visited[c-97] = true;\n                        }\n                        count[text.charAt(i)-97]--;\n                }\n\n                String out = "";\n\n                while(!s.isEmpty()){\n                        out = s.pop() + out;\n                }\n\n                return out;\n    }\n}\n```
[]