We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 713699a commit 9091decCopy full SHA for 9091dec
python3/2070.py
@@ -0,0 +1,26 @@
1
+class Solution:
2
+ def maximumBeauty(self, items: List[List[int]], queries: List[int]) -> List[int]:
3
+ # calculate max beauty for each price in items
4
+ beautyMap = defaultdict(int)
5
+ maxVal = 0
6
+ items.sort()
7
+ for x, y in items:
8
+ maxVal = max(maxVal, y)
9
+ beautyMap[x] = max(beautyMap[x], maxVal)
10
+
11
+ # binary search
12
+ prices = list(beautyMap.keys())
13
+ res = []
14
+ for q in queries:
15
+ if q < prices[0]:
16
+ res.append(0)
17
+ continue
18
+ l, r = 0, len(prices) - 1
19
+ while l < r:
20
+ m = (l + r + 1) // 2
21
+ if prices[m] <= q:
22
+ l = m
23
+ else:
24
+ r = m - 1
25
+ res.append(beautyMap[prices[l]])
26
+ return res
0 commit comments