Heap - Java O(N*logN)|O(N)
Intuition\n Describe your first thoughts on how to solve this problem. \nUse Heap to track the characters lexicographical order. Mark the top one as \' \' when 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nUse `Heap` to track the characters lexicographical order. Mark the top one as \' \' when encounter \'*\'.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$O(N*logN)$$ \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```java []\nclass Solution {\n    public String clearStars(String s) {\n        char[] arr = new char[s.length()];\n        PriorityQueue<Integer> pq = new PriorityQueue<>((a, b) -> arr[a] == arr[b] ? b - a : arr[a] - arr[b]);\n        int idx = 0;\n        for (char ch : s.toCharArray()) {\n            if (ch != \'*\') {\n                arr[idx++] = ch;\n                pq.offer(idx - 1);\n            } else {\n                while (arr[pq.peek()] == \' \')\n                    pq.poll();\n                arr[pq.peek()] = \' \';\n            }\n        }\n        StringBuilder sb = new StringBuilder();\n        for (char ch : arr) {\n            if (ch == 0)\n                break;\n            if (ch != \' \')\n                sb.append(ch);\n        }\n        return sb.toString();\n    }\n}\n```
['Java']