Most Beautiful Item for Each Query LeetCode solution in Python
1# Runtime: 2544 ms (Top 32.35%) | Memory: 73.6 MB (Top 48.94%)2class Solution:3def maximumBeauty(self, items: List[List[int]], queries: List[int]) -> List[int]:45items.sort()6dic = dict()7res = []8gmax = 09for p, b in items:10gmax = max(b, gmax)11dic[p] = gmax1213keys = sorted(dic.keys())14for q in queries:15ind = bisect.bisect_left(keys, q)16if ind < len(keys) and keys[ind] == q:17res.append(dic[q])18elif ind == 0:19res.append(0)20else:21res.append(dic[keys[ind - 1]])2223return res