At 9:05 the low should be the max element of the array. As we cannot divide single book to two persons, the max pages book can be allocated to single person only. So we cannot have the answer less than the maximum of the array. I hope it makes sense :)
Brother honestly saying i haven't seen such a kind of teaching anywhere else.... your expressions along with your hand actions i was able to understand each and every step.. Thanks a lot🔥
How could someone possibly think of such an approach? Forget 40 mins interview, It would've taken me forever to build such logic. Human mind is truly amazing ❤
@@tanmaysinghal8370 No, brother it will not work when condition is true then new book pages is allotted to that new student and that time we have to make it equals not addition or else the condition will always be true try this input and check pages = [250 74 159 181 23 45 129 174] students = 6
I have a question. In the isPossible function the last line is if(allocatedstu>k) return false; return true; this means it will return true even if allocatedstudent is less than k(might be possible) which is not allowed right, because each student should be allocated at least one book.
Please drop a small feedback on this white board idea of teaching. Small typo at end, it will be pages=a[i] Follow me at Instagram for all updates: instagram.com/striver_79/
Amazing explanation like always but let me clarify time complexity analysis Let N = Number of Books arr[i] = Number of pages in ith book Binary Search Search Space = Low = minimum of arr[i] High = Sum of arr[i] (i -> 0 - N) For every search space mid-value we check allocationPossible (O(N) Can be optimised to O(1) with Prefix Sum TimeComplexity = O(N * Log(sum of arr - low)) The the value inside log is the search space. So Log(N) is very wrong. Please correct me if I am wrong. Thank you
@@SudhanshuKumar-lp1nr hello bro int isAllocated(vector& A,int num,int k){ int count=1,sum=0,flag=0; for(int i=0;ik) return 2; return 1; } int Solution::books(vector &A, int B) { sort(A.begin(),A.end()); int sum=0; for(int i=0;i
@@dutt_2302 bro no where in the video it was mentioned to SORT the array, why are you sorting it? Also why are returning 0/1/2 from your helper function.. return true/false and make it simple
wow there is literally no one who can explain such a complex problem so easily like you bro. your confidence in explaining it made it very clear. thank you
yes bro , we can do this and we can skip the condition at beginning in the for loop because its guaranteed that our barrier will always be >= max Of the array, so all array elements individually can fit in the barrier 💛
how this possible, because we have to find the minimum no of pages....if we assume that there is only one student then he will get the min from the array and that's the answer
@@chandankumarshaw216 we need to find the maximums in all possible allocations, and see which max is actually minimum.. if only ine student then we will allocate all books to him. And if there are n Students where n is array size, each student we wil give one book. In each case, one of the student will get tha maxm pages book, and in all the psbl cases , the minimum psbl maximum is only that particular max.. Dry run with some exmples. Crct me striver if iam wrong...
at 9:13, when deciding the minimum range, I think it should be the maximum of the given books array instead of the minimum from the array. when students and number of books are equal, the answer will be the maximum among the pages of the book and not the minimum one.
Thanks for the genuine efforts Bhaiya !! I have watched your all the videos and learnt a lot from your sde series, your graph series is like a gem ! bhaiya according to me.... teaching on pad is much more easier and effective 😅!! all the best bhaiya
9:00 - the low should be the max element of the array. the max pages book can be allocated to single person only. So we cannot have the answer less than the maximum of the array.
Initially we can assign low = max(of the array elements) and high = sum(of all the array elements) Because it will be the minimum of maximum allotted pages. And I have one more doubt isn't the time complexity of the binary search - Log(sum_of_all_elements - min_element) or Log(sum_of_all_elements - max_element) ??
Yes this way of teaching topoc is great,more visualization ,more presentable and better presence . great approach. Continue with that. Just one thing to point out- video editing can be better .
Awesome explanation as always. Keep the videos coming! Just a question, can't we take 'low' as the max of the array? Because in any given array, there would be a student (partition) having maximum number of pages, and hence the max sum would be greater than or equal to the max value. Taking 'low' as the max of the array would potentially reduce the search space.
this way of teaching is far better than the previous way. Pls continue teaching us in this way only btw you explained it exceptionally well👌👌 and thank you for all ur efforts that u r putting in for us🙏 More power to you bhaiyya 🙌
Binary search can be applied to a sorted array, What if question includes an unsorted array and we are not allowed to sort the array??? Then what will be the solution???
At 24:00 it should be pages = arr[i] otherwise that if loop condition will always be true . As we did student++ so we are reinitializing the vaule of pages as arr[i] as it will calculate the sum for the other student.
Big fan bro, Awesome work, But i feel you can binary search the is_possible function as well by using the extra space of N where you store "sum till now". this way, it can be done in log(n)*log(n) time a = [12, 34, 67, 90] sum_a = [12, 46, 113, 203] students = 3 def is_possible(left, b, settled, used_students): right = len(a) - 1 if settled == sum_a[-1]: return True, used_students while left > 1 if a[mid] > b: return False, used_students e_mid = sum_a[mid] - settled if e_mid students: return False, count return True, count print(is_possible(left=0, b=b, settled=0, used_students=0))
Steps to follow for this kind of problem step 1:Think of the search space. step 2:Than write the function which gonna tell us that the value is good for becoming the ans. step 3: If yes update ans move to left else move to right.
Bhai literally you're best in teaching complex problems into simple solutions want to see more such videos ahead. keep doing such good work and motivating students like us.
At 24:00 , after allocatedStudent += 1 , I think next line should be pages = arr[i] instead of pages += arr[i], because if we are moving to next student, there will be some value of pages for previous student (If I understood it correctly) Correct me if I am wrong, BTW great explanation, and whiteboard makes the explanation better
Thank you for this video. Incredible explanation. This problem felt so complicated for me at first, I didn't think I could solve it. You really helped simplify this!!!
Hello, At time 24:17 you have written pages+=arr[i] while it should pages = arr[i] as we will restart adding pages for current student. I was getting WA for this. Otherwise great explanation bro 👌
Well explained brother. I came to your video after watching gfg self paced course video on this topic. I didn't get much clarity of the approach there but the way you explained it, Hats off dude.🤘
great explanation as always!!! Also regarding the whiteboard, you just continue with whatever way makes you comfortable but you know our obsession with dark mode and dark IDEs so I personally liked the previous way but as long as you are teaching it's all good!!
axctually i was seeing the updated video of ur binary search but didnt got why low was maximum then i came to see this video but realised that it was wrong here so i understood what went wrong .
I have a doubt :- if(alloc-student>k) return false; (this is clear) else if( alloc-student==k) return true ; ( this is also clear, because this is one possible ans). Else if(alloc-student
Like always great bhaiya and really love your series. Mujh se pahle ds algo question solve hi nhi hote the but ab mujhe samajh bhi aachi tarah aa jata h bde aaram se. THANKS TO YOU FOR THE SAME
if(allocated > B) return false; return true; In above line, if allocated is lesser than B, that means all the students have not been allocated books. So why are we returning true here?
Allocated is not lesser than B .it means after the execution of for loop the pages will be assigned to each student under given conditions ie why return true..
Please watch our new video on the same topic: czcams.com/video/Z0hwjftStI4/video.html
At 9:05 the low should be the max element of the array. As we cannot divide single book to two persons, the max pages book can be allocated to single person only. So we cannot have the answer less than the maximum of the array. I hope it makes sense :)
Brother honestly saying i haven't seen such a kind of teaching anywhere else.... your expressions along with your hand actions i was able to understand each and every step.. Thanks a lot🔥
exactly my point i had seen his vlogs but to study i came here for the first time, it was so fun understanding the concept
At 23:59, there is a small problem, It's correct in the GitHub code though. It should be pages = arr[i], instead of pages += arr[i];
Right , or make page=0 , then pages+=arr[i];
@@vaibhavchhabra800 Yep, even I was thinking the same
Correct !!
good observaton
can you please get me the link of the github where the code is present ?
thank you
Now it really feels like we are sitting on our chair and our teacher is teching is on board like in the school
#Nostalgia
How could someone possibly think of such an approach?
Forget 40 mins interview, It would've taken me forever to build such logic.
Human mind is truly amazing ❤
at 24:33 Correction else condition ke andar pages = arr[i] hoga mistake se pages += arr[i] leka ja chuka hai
Page to plus hi honge bhai.... Agar same bande jo rha h to
@@tanmaysinghal8370 No, brother it will not work when condition is true then new book pages is allotted to that new student and that time we have to make it equals not addition or else the condition will always be true
try this input and check
pages = [250 74 159 181 23 45 129 174]
students = 6
Yes, Brother
Ig it should be pages = arr[i] in if condition!!
As soon as we increase student, we should reset pages
abbe chutiye else mein nhi but 2nd if mai pages=arr[i] hoga
I have a question. In the isPossible function the last line is
if(allocatedstu>k)
return false;
return true;
this means it will return true even if allocatedstudent is less than k(might be possible) which is not allowed right, because each student should be allocated at least one book.
same doubt ... If you have the solution why he did, Can you please tell me.
I have same doubt. Can someone pls explain??
No one can explain this , even striver bhaiya , that's why he ignore this comment.
such energy at 3 in the morning, we students are blessed to have people like you.
Bro paused at 0:49 to tell u that u look very cool while explaining on the white board........the vibe is so awsm...... honestly speaking
I have a doubt. I'll be glad if anyone could help. Why are we returning true when allocated students
Please drop a small feedback on this white board idea of teaching.
Small typo at end, it will be pages=a[i]
Follow me at Instagram for all updates: instagram.com/striver_79/
Please make a video on Which companies hire tier 3 BCA Students.... Please
@@AmanKumarSinhaOfficial yes
Yes, this idea is correct
bole to jhakaaass!!
super osm sir
Bhaiya great video , very crystal clear concept you discussed, and this white board adds 100X more value to us
Amazing explanation like always but let me clarify time complexity analysis
Let N = Number of Books
arr[i] = Number of pages in ith book
Binary Search Search Space = Low = minimum of arr[i] High = Sum of arr[i] (i -> 0 - N)
For every search space mid-value we check allocationPossible (O(N) Can be optimised to O(1) with Prefix Sum
TimeComplexity = O(N * Log(sum of arr - low))
The the value inside log is the search space. So Log(N) is very wrong.
Please correct me if I am wrong.
Thank you
Had the same doubts regarding TC. Seems correct.
You are correct i guees
In IsPossible function ,in If statement , instead of pages+=arr[i] it should be pages=arr[i]
Yes mentioned in description as well as pinned comment. Thankyou.
Can there be case where all the students are not allocated at least 1 book for a value of mid ???
@@SudhanshuKumar-lp1nr hello bro
int isAllocated(vector& A,int num,int k){
int count=1,sum=0,flag=0;
for(int i=0;ik) return 2;
return 1;
}
int Solution::books(vector &A, int B) {
sort(A.begin(),A.end());
int sum=0;
for(int i=0;i
@@dutt_2302 bro no where in the video it was mentioned to SORT the array, why are you sorting it? Also why are returning 0/1/2 from your helper function.. return true/false and make it simple
wow there is literally no one who can explain such a complex problem so easily like you bro. your confidence in explaining it made it very clear. thank you
A slight optimization is that the range lies between Max(arr) - Sum(arr), instead of Min(arr) - Sum(arr)
Yes we can do this.. thanks
yes bro , we can do this and we can skip the condition at beginning in the for loop because its guaranteed that
our barrier will always be >= max Of the array, so all array elements individually can fit in the barrier 💛
how this possible, because we have to find the minimum no of pages....if we assume that there is only one student then he will get the min from the array and that's the answer
@@chandankumarshaw216 we need to find the maximums in all possible allocations, and see which max is actually minimum.. if only ine student then we will allocate all books to him.
And if there are n Students where n is array size, each student we wil give one book. In each case, one of the student will get tha maxm pages book, and in all the psbl cases , the minimum psbl maximum is only that particular max..
Dry run with some exmples.
Crct me striver if iam wrong...
@@sandeepnallala48 okk thanks
No article ever gave me this clear intuition for implementing binary search in an unsorted array. AMAZING!!
I think there is one one edge case added into the main method which is - If(number_of_Students > A.length) return -1;
This is amazing and a favorable methodology for learning.❤️💯💯
The initial left limit of the search space should be 90 instead of 12. Which is the value max value present in the array.
I would believe the minimumValue should be the maximum of (arr[I]) , For example -> A = [5, 17, 100, 11]B = 4
here low=100, and high=SumofArr[I].
Energy & explanation 😍🔥
at 9:13, when deciding the minimum range, I think it should be the maximum of the given books array instead of the minimum from the array.
when students and number of books are equal, the answer will be the maximum among the pages of the book and not the minimum one.
Thanks for the genuine efforts Bhaiya !! I have watched your all the videos and learnt a lot from your sde series, your graph series is like a gem !
bhaiya according to me.... teaching on pad is much more easier and effective 😅!!
all the best bhaiya
Yes easier but usually in pad, i cannot show hand expressions, which in turn makes it very tough to communicate my thought.
@@takeUforward bhyaiya please make more videos on algorithms whenever u get time❣️❣️..it's really helpful
9:00 - the low should be the max element of the array. the max pages book can be allocated to single person only. So we cannot have the answer less than the maximum of the array.
Initially we can assign low = max(of the array elements) and high = sum(of all the array elements)
Because it will be the minimum of maximum allotted pages.
And I have one more doubt isn't the time complexity of the binary search - Log(sum_of_all_elements - min_element) or Log(sum_of_all_elements - max_element) ??
Want a tree series as well🙏
Presented ❤️
@@striver_79 watching 💜
Amazing explanation bhaiya💯
Words won't suffice for the way of teaching you provide!!!! ❤
@Ayesha tell me one thing the time complexity of binary search is wrong in the video since the search space is not N but its M = (Sum(arr)-Max(arr)+1)
UNDERSTOOD.... !!!
Long life to the LEGEND.... :)
The answer lies in between 90 -203 I think ie the low will be the maximum in array but anyways that doesn't make any significant TC difference
Best Explaination Whiteboard se concept aur clear hogaya waiting for your complete sde sheet to complete. ❤👌👍
Respect for Hard work you are doing.
Yes this way of teaching topoc is great,more visualization ,more presentable and better presence .
great approach. Continue with that.
Just one thing to point out- video editing can be better .
Yes working on it..
Awesome explanation as always. Keep the videos coming!
Just a question, can't we take 'low' as the max of the array? Because in any given array, there would be a student (partition) having maximum number of pages, and hence the max sum would be greater than or equal to the max value.
Taking 'low' as the max of the array would potentially reduce the search space.
A slight correction on 24:03
if( pages+arr[i] > barrier){
allocatedStu++;
pages = arr[i] // Instead of pages+=arr[i];
}
Read pinned comment. 😵💫
Saw your LinkedIn post sir.
This white board is surely a boon for our learning.
Nice and unique explanation striver thanks a lot
Anyone one who is looking to learn DSA - this is the best channel I think. It will certainly take u forward.
I can understand it takes energy to speak so clearly and explain.......thanks. God bless you success.
came here after Binary Search Master Class, although i have done this question but wanted to go through your video once
Amazing understood the whole approach ,You r just cool.
this way of teaching is far better than the previous way. Pls continue teaching us in this way only
btw you explained it exceptionally well👌👌 and thank you for all ur efforts that u r putting in for us🙏
More power to you bhaiyya 🙌
You made the complexity so easy... Thank you so much for the explanation
Bhai ek dum se 🔥🔥🔥 2-3 videos me samajh me nahi aa Raha tha.. aapke videos se pura concept pata lag gaya
2-3 videos dekhna hi kyu h jb TUF ka video h XD
Binary search can be applied to a sorted array,
What if question includes an unsorted array and we are not allowed to sort the array???
Then what will be the solution???
I am applying binary search on the search space bro, not on the array. Carefully see. Please watch my previous videoszz
At 24:00 it should be pages = arr[i] otherwise that if loop condition will always be true . As we did student++ so we are reinitializing the vaule of pages as arr[i] as it will calculate the sum for the other student.
This setup is a great upgrade brother.
P.S. best online lecture of my life❤️
Big fan bro, Awesome work, But i feel you can binary search the is_possible function as well by using the extra space of N where you store "sum till now".
this way, it can be done in log(n)*log(n) time
a = [12, 34, 67, 90]
sum_a = [12, 46, 113, 203]
students = 3
def is_possible(left, b, settled, used_students):
right = len(a) - 1
if settled == sum_a[-1]:
return True, used_students
while left > 1
if a[mid] > b:
return False, used_students
e_mid = sum_a[mid] - settled
if e_mid students:
return False, count
return True, count
print(is_possible(left=0, b=b, settled=0, used_students=0))
Dude made the funniest algo tutorial!=
Appreciate man for using pen and board
This much of energy at 3:00 AM with such an amazing explanation, man you're great, hats-off.
Steps to follow for this kind of problem
step 1:Think of the search space.
step 2:Than write the function which gonna tell us that the value is good for becoming the ans.
step 3: If yes update ans move to left else move to right.
one of the best video i have seen with the kind of explation and dedication
Thanku for this
Back to basics. Whiteboard tutorials gives a great vibe for learning!!
Raj Bhaiya, the energy with which the video is made, it was so engaging ,so crisp and clear! Thankyou so much brother!
So nice of you
I have fallen in love with your teaching style! You can teach us whatever you like!
Bhai literally you're best in teaching complex problems into simple solutions want to see more such videos ahead.
keep doing such good work and motivating students like us.
Great approach...never thought one could explain binary search soo easily..
small correction Bro
at 23:59
pages = arr[i];
BTW Love your content Brother!!
I was looking for this correction only in the comments otherwise I was going to post.... Thanks
But how please explain I did't get it..🙏
the explanation was as clear as a crystal . I could'nt understand the question but now it totally clear. THANKS A LOT !!!
The video helped me realize the power of binary search. Didn't know it could be used in such a way. Thank you.
striver bhaiya❤ are bhaiya itni clearity ke sath to koi nhi pdata h aap to yaar really me hard se hard problem ko bhi aasani se easy kr dete ho
At 24:00 , after allocatedStudent += 1 , I think next line should be pages = arr[i] instead of pages += arr[i], because if we are moving to next student, there will be some value of pages for previous student (If I understood it correctly)
Correct me if I am wrong, BTW great explanation, and whiteboard makes the explanation better
I have updated about this in the pinned comment and description. Thanks
Thank you for this video. Incredible explanation. This problem felt so complicated for me at first, I didn't think I could solve it. You really helped simplify this!!!
bro tell me one thing the time complexity of binary search is wrong in the video since the search space is not N but its M = (Sum(arr)-Max(arr)+1)
Thank You So Much Striver Brother...........🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
kudos to your efforts to making such type of videos for us.
inside the isPossible function inside first if condition it should be pages=arr[i] instead of pages+=arr[I
]
bro your explanation is just next level. i don't think i will ever ever forget this queston
do you have the github link for this question
Best explanation on this problem
Hello, At time 24:17 you have written pages+=arr[i] while it should pages = arr[i] as we will restart adding pages for current student. I was getting WA for this.
Otherwise great explanation bro 👌
Thanks for explaining the search space idea. This gives the intuition for using binary search in such problems.
Sorry to say Apni kasha ka dekhkr aaya explanation .. smjh me nhi aaya .
but raj bhaiya ka dekhkr aa gya smjhe me
thanks alot bhaiya
I almost gave up on this question, but your explanation exceeded my highest expectations, you deserve a lot more sir, hats off to you.
Well explained brother. I came to your video after watching gfg self paced course video on this topic. I didn't get much clarity of the approach there but the way you explained it, Hats off dude.🤘
great explanation as always!!! Also regarding the whiteboard, you just continue with whatever way makes you comfortable but you know our obsession with dark mode and dark IDEs so I personally liked the previous way but as long as you are teaching it's all good!!
Why yur allocate fn return true even stuents
bruh I honestly don't know how someone can devote himself completely to teaching!!!
bhaiya maaja aa gya ekdum feeel aaa gyaa bhaiyaaaa ekdum ..loved white board...bhaiya aage ki videos white board pe bnana bhaiya
Bhai if I was not in 3 year I would have been Google ready kya he revision horha op stuff brother keep it up..
axctually i was seeing the updated video of ur binary search but didnt got why low was maximum then i came to see this video but realised that it was wrong here so i understood what went wrong .
Excellent Explaination !
I have a doubt :-
if(alloc-student>k)
return false; (this is clear)
else if( alloc-student==k)
return true ; ( this is also clear,
because this is one possible ans).
Else if(alloc-student
those small tips about interview like not telling dp solution to save time makes this channel special
The teaching way is Phenomenal 🔥🔥
actually, we have to return false even when alllocstu = k , so as to find the min pages (kind of like how lower bound works)
int when int is starting with 0, but in the video his count is starting with 1.
Better than last mode of teaching ❤️❤️❤️🔥🔥🔥🔥🎉🎉🎉
low will be the maximum element of the array right? not the minimum element of array naa?
Like always great bhaiya and really love your series. Mujh se pahle ds algo question solve hi nhi hote the but ab mujhe samajh bhi aachi tarah aa jata h bde aaram se. THANKS TO YOU FOR THE SAME
How enthusiastic! Helps me a lot! May all girls of the world have crush on you..................................
How can anyone be so fresh while teaching at 3AM?!!! Thumbs up bro
at 24:02 It should be pages = arr[i], instead of pages += arr[i] or make page=0 and then pages+=arr[i];
great effort.
This is the best intuition behind this problem ever!!! Thanks, bhaiya!!!
Thank you striver❤
It's really inspiring to see that you are putting so much efforts for us. Thank you!
if(allocated > B)
return false;
return true;
In above line, if allocated is lesser than B, that means all the students have not been allocated books. So why are we returning true here?
I'm also have the same doubt. If you get the answer please share here bro
Allocated is not lesser than B .it means after the execution of for loop the pages will be assigned to each student under given conditions ie why return true..
your teaching method is very attractive,
wish u all the best
if(n
I have the same doubt ... But how should we update our search space in such a case case