JAVA || Stack || 63ms
Complexity\n- Time complexity:  O(n) \n Add your time complexity here, e.g. O(n) \n\n- Space complexity:  O(n) \n Add your space complexity here, e.g. O(n) \n\n
# Complexity\n- Time complexity: $$ O(n) $$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$ O(n) $$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public String clearStars(String s) {\n        int[] f = new int[26];\n        List<Stack<Integer>> ind = new ArrayList<>();\n        for(int i=0;i<26;i++){\n            ind.add(new Stack<>());\n        }\n        char[] w = s.toCharArray();\n        for(int i=0;i<w.length;i++){\n            if(w[i]==\'*\'){\n                w[i]=\'$\';\n                int j=0;\n                for(j=0;j<26;j++){\n                    if(f[j]>0){\n                        break;\n                    }\n                }\n                w[ind.get(j).pop()]=\'$\';\n                f[j]--;\n            }else{\n                f[w[i]-\'a\']++;\n                ind.get(w[i]-\'a\').add(i);\n            }\n        }\n        StringBuilder str = new StringBuilder();\n        for(char ch:w){\n            if(ch!=\'$\'){\n                str.append(ch);\n            }\n        }\n        return str.toString();\n    }\n    \n}\n```
['Stack', 'Java']