Solution with using map and set
\n\n# Code\n\nclass Solution {\n    public String smallestSubsequence(String s) {\n        Map<Character,Integer> map = new HashMap<>();\n        for(int i = 0;
\n\n# Code\n```\nclass Solution {\n    public String smallestSubsequence(String s) {\n        Map<Character,Integer> map = new HashMap<>();\n        for(int i = 0;i < s.length();i++){\n            map.put(s.charAt(i),map.getOrDefault(s.charAt(i),0) + 1);\n        }\n        Set<Character> set = new HashSet<>();\n        Stack<Character> stack = new Stack<>();\n        for(int i = 0;i < s.length();i++){\n            if(!set.contains(s.charAt(i))){\n                while(!stack.isEmpty() && stack.peek() > s.charAt(i) && map.containsKey(stack.peek())){\n                    set.remove(stack.pop());\n                }\n                set.add(s.charAt(i));\n                stack.push(s.charAt(i));\n            }\n            if(map.get(s.charAt(i)) == 1){\n                map.remove(s.charAt(i));\n            }else{\n                map.put(s.charAt(i),map.get(s.charAt(i)) - 1);\n            }\n        }\n        StringBuilder sb = new StringBuilder();\n        while(!stack.isEmpty()){\n            sb.insert(0,stack.pop());\n        }\n        return String.valueOf(sb);\n    }\n}\n```
['Hash Table', 'Stack', 'Monotonic Stack', 'Java']