Easy Java Solution || Sorting || Beats 100%
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public String clearStars(String s) {\n        int n = s.length();\n\n        ArrayList<Integer> arr[] = new ArrayList[26];\n        for(int i=0; i<26; i++) arr[i] = new ArrayList<>();\n        for(int i=0; i<n; i++){\n            char ch = s.charAt(i);\n\n            if(ch==\'*\'){\n                for(int k=0; k<26; k++){\n                    if(arr[k].size()!=0){\n                        arr[k].remove(arr[k].size()-1);\n                        break;\n                    }\n                }\n            }else{\n                arr[ch-\'a\'].add(i);\n            }\n        }\n\n        ArrayList<int[]> a = new ArrayList<>();\n        for(int i=\'a\'; i<=\'z\'; i++){\n            for(var x : arr[i-\'a\']){\n                a.add(new int[]{i,x});\n            }\n        }\n\n        StringBuilder ans = new StringBuilder();\n        \n        Collections.sort(a,(x,y)->x[1]-y[1]);\n        \n        for(var x : a){\n           \n            ans.append((char)x[0]);\n        }\n        return ans.toString();\n    }\n}\n```
['Java']