Leetcode 3281 Maximize Score of Numbers in Ranges

preview_player
Показать описание
Using binary search on answer , explained the thought process in easy manner in Hindi
Maximize Score of Numbers in Ranges | Hindi
Leetcode 3281. Maximize Score of Numbers in Ranges
3281 Maximize Score of Numbers in Ranges
3281. Maximize Score of Numbers in Ranges
Leetcode 3281. Maximize Score of Numbers in Ranges
Leetcode contest 414
today's leetcode contest 414
Leetcode Maximize Score of Numbers in Ranges
Maximize Score of Numbers in Ranges leetcode
leetcode 3281 hindi

Leetcode contest 411

Leetcode 3281 todays leetcode contest Question
Leetcode 3281 leetcode contest
Leetcode 3281

LEETCODE CONTEST "414" CHALLENGE - VERY SIMPLE EXPLANATION with SIMPLE CODE.

Time Complexity of Incrementing the "LIKE" Variable: "LIKE++;" --- O(1)
Time Complexity of "SUBSCRIBING" to the channel: "SUBSCRIBE++;" -- O(1)
But yeah Time Complexity of Commenting is somewhat higher: O(size of comment), maybe you can reduce it by just commenting with an emoji 😉
Рекомендации по теме
Комментарии
Автор

Like! SUBSCRIBE! Comment!
Below is the code :

Code :

class Solution {
public:
bool check(long long x, vector<long long> &start, int d){
long long curr=start[0];
for(int i=1;i<start.size();i++){
if(start[i]>curr+(long long )x){
curr=start[i];
}
else if(curr+(long long)x <= (long long )start[i]+(long long )d){
curr = curr+x;
}
else{
return 0;
}
}

return 1;
}
int maxPossibleScore(vector<int>& s, int d) {

vector<long long > start;
for(int i=0;i<s.size();i++){
start.push_back((long long )s[i]);
}

sort(start.begin(), start.end());

int l=0;
int
int ans=0;

while(l<=r){
long long mid=l+(r-l)/2;
if(check(mid, start, d)){
ans=mid;
l=mid+1;
}
else{
r=mid-1;
}
}

return ans;
}
};

Think_Code
Автор

Saw a lot of videos overcomplicating this. simplest solution there is.

bhavukkalra
Автор

Can you please explain, why you took low as 0 for starting condition of Binary Search.
Suppose you have array: [0, 4, 8] and d=1.

Here the minimum valid difference shouldn't be: 4

I have doubt for this not being Monotonic in this way.

pranjal-barnwal
Автор

bro one question is sorting the given array wont effect the absolute difference of orignal array

latestmovies
Автор

The best video I found for this question. Huge shoutout!

shristisrivastava