Skip to content

Commit

Permalink
Create 2070. Most Beautiful Item for Each Query (#633)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chayandas07 authored Nov 12, 2024
2 parents 771a47b + 5695963 commit c555d0e
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions 2070. Most Beautiful Item for Each Query
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Solution {
public:
vector<int> maximumBeauty(vector<vector<int>>& items, vector<int>& queries) {
vector<vector<int>> v;
int n = queries.size();
for(int i = 0; i < n; i++){
v.push_back({queries[i],i});
}
sort(v.begin(),v.end());
sort(items.begin(),items.end());
vector<int> ans(n);
int j=0;
n = items.size();
int mx = 0;
for(auto &i: v){
while(j<n && items[j][0]<=i[0]){
mx = max(mx,items[j][1]);
j++;
}
ans[i[1]] = mx;
}
return ans;
}
};

0 comments on commit c555d0e

Please sign in to comment.