if nums[i]%mid==0, then people may assume that it'll take (nums[i]//mid) operations to reduce it in a way that maximum number becomes equal to mid. But that's wrong, it'll take ((nums[i]-1)//mid) operations. Anyways, thanks for the fantastic solution
Fraz in the timeframe 9:00 at first you divided the value by 2 and reduced with minus (-1) but when you dividing it with 3 why you didn't subtracted with -1?
Brother, I have a doubt, sometimes we are returning L or R in binary search or in other cases storing our ans is a variable & returning it. How to decide ?
@@mohammadfraz int minimumSize(vector& A, int k) { int left = 1, right = 1e9; while (left < right) { int mid = (left + right) / 2, count = 0; for (int a : A) count += (a - 1) / mid; if (count > k) left = mid + 1; else right = mid; } return left; see lee's code- he is returning left and mid=(left+right)/2 instead of (right+(right-left)/2) ,later one gives error/wrong ans is some problems even his looping condition is different. I have seen this many times but didn't understand the variations. could you please explain?
@@learner_1228 that is why I was trying to keep it simple in my series. I never return l or r. Don't see so many codes if it's confusing you. Stick to one.
Yes , So let say you have 7 and you want to make parts of 7 such that no part is bigger thn 2 Thn 7=(2,5)=(2,2,3)=(2,2,2,1) So you took 3 moves That is equal to 7/2 And let's say you have 8 Thn 8=(2,2,2,2) you took 8/2 -1 moves So number of moves you take is qual to nums[i]/x(min allowed number) -1 if nums[I] is divisible by x And it's nums[i]/x if nums[I] is not divisible by x
Nope. First operation is when we divide 7 into 6 and 1. Second operation is when we divide 17 into 11 and six. And finally third operation is when we further divide 11 in five and so in total there are three operations
instead of using INT_MAX ,can we use maximum element in nums array?
Definitely you can
Yes, I use Math.max(...nums) in JS and it's working.
@@jimmyliao6429 great
Thanks for making it so simple!!
Awesome Mohammad, thanks a lot! by the way what is the name of the editor you're using for explanation?
if nums[i]%mid==0, then people may assume that it'll take (nums[i]//mid) operations to reduce it in a way that maximum number becomes equal to mid. But that's wrong, it'll take ((nums[i]-1)//mid) operations.
Anyways, thanks for the fantastic solution
Thanks for sharing this, super helpful! Keep it up, this is awesome! :D
Thanks a lot , it's motivating
Nice explanation sir....your videos are really helpful....keep making more videos
Nice explanation, Binary Search is amazing to me in this question.
And also in last weekly contest question
Closest Subsequence Sum
leetcode.com/problems/closest-subsequence-sum/
Thanks 😊
Thanks a lot. Very helpful and nice explanation💥
Thanks a lot
very nice explanation! the binary search is a nice touch. I could not come up with a solution during the contest.
Thanks 😊
Amazing! Liked and subbed!
Thanks a lot 😊
What will be the time complexity?
Fraz in the timeframe 9:00 at first you divided the value by 2 and reduced with minus (-1) but when you dividing it with 3 why you didn't subtracted with -1?
is that due to that fact that m(8) is not a factor of the value 4 and 8. If its a factor we need to reduce the result with -1? am i right
nice pls upload the solution of zuma game on leetcode
Thanks a lot!!! :D
You're welcome
Brother, I have a doubt, sometimes we are returning L or R in binary search or in other cases storing our ans is a variable & returning it. How to decide ?
In no example I have return l or r.
I always store in ans
@@mohammadfraz int minimumSize(vector& A, int k) {
int left = 1, right = 1e9;
while (left < right) {
int mid = (left + right) / 2, count = 0;
for (int a : A)
count += (a - 1) / mid;
if (count > k)
left = mid + 1;
else
right = mid;
}
return left;
see lee's code- he is returning left and mid=(left+right)/2 instead of (right+(right-left)/2) ,later one gives error/wrong ans is some problems
even his looping condition is different.
I have seen this many times but didn't understand the variations.
could you please explain?
@@learner_1228 that is why I was trying to keep it simple in my series.
I never return l or r.
Don't see so many codes if it's confusing you. Stick to one.
Can you explain the mathematics part? I dont get it.
Yes ,
So let say you have 7 and you want to make parts of 7 such that no part is bigger thn 2
Thn 7=(2,5)=(2,2,3)=(2,2,2,1)
So you took 3 moves
That is equal to 7/2
And let's say you have 8
Thn 8=(2,2,2,2) you took 8/2 -1 moves
So number of moves you take is qual to nums[i]/x(min allowed number) -1 if nums[I] is divisible by x
And it's nums[i]/x if nums[I] is not divisible by x
Please increase the text size in leetcode also zoon in the screen while recording the solution!!
I always forget to do it , will keep in mind
@@mohammadfraz Thank you for taking it into consideration 🙏
Ngl, Q4 was easier and straight forward kaafi this time
Q3 strike hi nhi hua kuch during contest
Okay , is it clear from the video
@@mohammadfraz Yes. Definitely🤘🏻
At 6:13, how did you use 3 operations? I think its still 2 operations only : [7, 17] -> [6, 1 , 11, 6] -> [6, 1, 6, 5, 6]
Nope. First operation is when we divide 7 into 6 and 1. Second operation is when we divide 17 into 11 and six. And finally third operation is when we further divide 11 in five and so in total there are three operations
@@panavkumar9009 thanks