Skip to content

Commit 1c3aa1b

Browse files
committed
Time: 46 ms (53.62%), Space: 81.4 MB (37.28%) - LeetHub
1 parent f7f3a8f commit 1c3aa1b

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
class Solution {
2+
public int[] maximumBeauty(int[][] items, int[] queries) {
3+
4+
// Idea -- Sort the array based on 1st indx .
5+
// Binary Search the array
6+
7+
int n = items.length;
8+
Arrays.sort(items,(a,b)->(a[0]==b[0])?(b[1]-a[1]):(a[0]-b[0]));
9+
10+
int maxi = Integer.MIN_VALUE;
11+
for(int i=1;i<n;i++){
12+
items[i][1] = Math.max(items[i-1][1] , items[i][1]);
13+
14+
}
15+
16+
int[] res =new int[queries.length];
17+
for(int i=0;i<queries.length;i++){
18+
int start = 0;
19+
int end = n-1;
20+
while(start<=end){
21+
int mid = start+(end-start)/2;
22+
if(items[mid][0]<=queries[i]){
23+
start = mid+1 ;
24+
res[i] = Math.max(res[i] , items[mid][1]);
25+
}else{
26+
end = mid-1;
27+
}
28+
}
29+
30+
}
31+
return res;
32+
33+
}
34+
}

0 commit comments

Comments
 (0)