Min Heap | Delete nearest left smallest
Intuition\nUsing mean heap we can find nearest least smallest element.\n\n\n# Complexity\n- Time complexity: O(nlog(n))\n Add your time complexity here, e.g. O(
# Intuition\nUsing mean heap we can find nearest least smallest element.\n\n\n# Complexity\n- Time complexity: $$O(nlog(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    def clearStars(self, s: str) -> str:\n        deleted = set()\n        heap = []\n        for i, ch in enumerate(s):\n            if ch == \'*\':\n                _, idx = heappop(heap)\n                deleted.add(-idx)\n                deleted.add(i)\n            else:\n                heappush(heap, (ch, -i))\n        ans = \'\'\n        for i, ch in enumerate(s):\n            if i not in deleted and ch !=\'*\':\n                ans += ch\n        return ans\n\n```\n\n![upvote-0.jpeg](https://assets.leetcode.com/users/images/dabdbee4-62cf-49ec-b18c-2f238092a566_1717303165.2118626.jpeg)\n\n
['Heap (Priority Queue)', 'Python3']