Chocolate Distribution problem | Q30 | Love Babbar DSA Sheet
Vložit
- čas přidán 9. 07. 2024
- #competitiveprogramming #dsasheet #interviewpreparation
In this video I have solved the 30th problem of the sheet i.e. Chocolate Distribution problem.
String question Playlist = • Love Babbar DSA 450 Qu...
Array question Playlist = • Love Babbar DSA 450 Qu...
Love Babbar DSA Sheet : drive.google.com/file/d/1FMdN...
Hope you like it. Comment if you have any doubt.
LIKE | SHARE | SUBSCRIBE
Can we solve this problem in the time complexity of O(n) ?
maaza aa gayi ... you made the code explaination so easy .Thanku sir
why are u taking i+m-1
A window is of size m , so the last(max) element of window is at position i+m-1 , and we substract max-min in each window
how did you clear the driver code ?
thanku so much bhaiya
Awesome Bro Keep it Up..................................
Awesome 👌👌👌👍👍👌
I dont get it how they classified this as easy problem
how did you know in yoiur mind that it will be i+m-1 ?? Why not consider something else ?
Sir, how the time complexity is O[nlogn] in your case?
because of sort function
i am not getting correct answer in this approach by simple pick and non pick please help:
long long solve(int index,int current_q,int t_q,vector &input,long long mmin,long long mmax){
if(index >=input.size()) return INT_MAX; //toal elents le nhi paya answer nhi nikal payega
if(current_q==t_q) { //total reach ho gya
return abs(mmin-mmax);
}
for(int i=index+1;immax){
newmax=input[i];
}
if(input[i]
Can u tell what is the reason to do sorting first?
We are using greedy approach, so by sorting for each window we get min element in 1st index of window and max element in last index of window
why we are sorting the array.Can you please brief this approach
We are using greedy approach, so by sorting for each window we get min element in 1st index of window and max element in last index of window
Nice explanation but when I initialise min with INT_MAX I do not get the desired output.What should I do?
just give 999 or any big integer ! or u can include header file
Hey btw why we initialise int min = INT_MAX means why we don't do Int min = INT_MIN why it is opposite
@@kriptoedits9978 because as we want our answer to be minimim so for comparison we want something which is bigger than that particular number at which we are currently sitting though we can also take a bigger number like 999 but its good practise to use INT_MAX for it ..and it is opposite if in case we want our answer to be minimum then at that point we initialize it as INT_MIN (or we can also take it as 0)
Use #include
Bhai strings pe ana toh 3-5 questions karna per day. Please bhai
is there any solution other than sorting...?
No
give me some tips to increase thinking power of such type of questions.
try questions regularly. it will happen automatically.!!
Tumko ksm h bell icon ki ydi ye series bich m bnd ki to ❤️ mohhbt h
are bhai code hi padna tha to tumhari video kyu dhekhae
really
I am not able to understand from ur video
Explanation is not very clear. Just iterating through the solutions.
Sir first explain the question then provide solutions.
Are bhayya why don't u speak in English
bhai tune sirf code karke dikhaya logic to bataya hi nai gfg solution me se dekh ke to koi bhi upload kar sakta hain. question ko thik se samjana sikho youtube me add se paise kamane ke liye kuch bhi mat karo
Tbh this problem is poorly constructed
No explanation.😂😂only write the code.dont waste our time bro
long long findMinDiff(vector arr, long long n, long long m){
//code
sort(arr.begin(),arr.end());
long long i=0,j=0,mx=INT_MIN,mn=INT_MAX,res=INT_MAX;
while(j