Python Elegant & Short | Sorting & Prefix Max & Binary Search
Complexity\n- Time complexity: O((n + m) * \log_2 {n}), where m - length of queries\n- Space complexity: O(n)\n\n# Code\npython3 []\nclass Solution:\n    def ma
# Complexity\n- Time complexity: $$O((n + m) * \\log_2 {n})$$, where $$m$$ - length of queries\n- Space complexity: $$O(n)$$\n\n# Code\n```python3 []\nclass Solution:\n    def maximumBeauty(self, items: list[list[int]], queries: list[int]) -> list[int]:\n        prices = []\n        beauties = [0]\n\n        for price, beauty in sorted(items):\n            prices.append(price)\n            beauties.append(max(beauties[-1], beauty))\n\n        max_beauty = []\n\n        for max_price in queries:\n            idx = bisect(prices, max_price)\n            max_beauty.append(beauties[idx])\n\n        return max_beauty\n```\n
['Binary Search', 'Sorting', 'Prefix Sum', 'Python', 'Python3']