📌📌 Well-Explained || 99% faster || Mainly for Beginners 🐍
IDEA :\n\n Step 1. Sort the items by price, O(nlog)\n\n Step 2. Iterate items, find maximum value up to now, O(n) and store the max value in dictionary(MAP) her
## IDEA :\n\n* Step 1. Sort the items by price, O(nlog)\n\n* Step 2. Iterate items, find maximum value up to now, O(n) and store the max value in dictionary(MAP) here `dic`.\n* Step 3. For each queries, binary search the maximum beauty, O(log k) in key of the map which we formed and append the max value of the query from dictionary in O(1) .\n* Step 4. Whole process is doen in `O(q+n)` though.\n\n**Impementation :**\n\'\'\'\n\n\tclass Solution:\n\t\tdef maximumBeauty(self, items: List[List[int]], queries: List[int]) -> List[int]:\n\n\t\t\titems.sort()\n\t\t\tdic = dict()\n\t\t\tres = []\n\t\t\tgmax = 0\n\t\t\tfor p,b in items:\n\t\t\t\tgmax = max(b,gmax)\n\t\t\t\tdic[p] = gmax\n\n\t\t\tkeys = sorted(dic.keys())\n\t\t\tfor q in queries:\n\t\t\t\tind = bisect.bisect_left(keys,q)\n\t\t\t\tif ind<len(keys) and keys[ind]==q:\n\t\t\t\t\tres.append(dic[q])\n\t\t\t\telif ind==0:\n\t\t\t\t\tres.append(0)\n\t\t\t\telse:\n\t\t\t\t\tres.append(dic[keys[ind-1]])\n\n\t\t\treturn res\n\t\n### \tThanks and Upvote if you like the Idea !!\u270C
['Binary Search Tree', 'Sorting', 'Python', 'Python3']