Skip to content

Commit 5695963

Browse files
authored
Create 2070. Most Beautiful Item for Each Query
1 parent 771a47b commit 5695963

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution {
2+
public:
3+
vector<int> maximumBeauty(vector<vector<int>>& items, vector<int>& queries) {
4+
vector<vector<int>> v;
5+
int n = queries.size();
6+
for(int i = 0; i < n; i++){
7+
v.push_back({queries[i],i});
8+
}
9+
sort(v.begin(),v.end());
10+
sort(items.begin(),items.end());
11+
vector<int> ans(n);
12+
int j=0;
13+
n = items.size();
14+
int mx = 0;
15+
for(auto &i: v){
16+
while(j<n && items[j][0]<=i[0]){
17+
mx = max(mx,items[j][1]);
18+
j++;
19+
}
20+
ans[i[1]] = mx;
21+
}
22+
return ans;
23+
}
24+
};

0 commit comments

Comments
 (0)