Skip to content

Commit f20b892

Browse files
authored
Create most-beautiful-item-for-each-query.py
1 parent c82a09c commit f20b892

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Time: O(nlogn + qlogn)
2+
# Space: O(1)
3+
4+
import bisect
5+
6+
7+
class Solution(object):
8+
def maximumBeauty(self, items, queries):
9+
"""
10+
:type items: List[List[int]]
11+
:type queries: List[int]
12+
:rtype: List[int]
13+
"""
14+
items.sort()
15+
for i in xrange(len(items)-1):
16+
items[i+1][1] = max(items[i+1][1], items[i][1])
17+
result = []
18+
for q in queries:
19+
i = bisect.bisect_left(items, [q+1])
20+
result.append(items[i-1][1] if i else 0)
21+
return result

0 commit comments

Comments
 (0)