BS-18. Allocate Books or Book Allocation | Hard Binary Search

แชร์
ฝัง
  • เผยแพร่เมื่อ 20 ก.ย. 2024

ความคิดเห็น • 307

  • @manrar8419
    @manrar8419 ปีที่แล้ว +160

    Hi Raj, Hriday here...I have been following your SDE sheet for a while, and I'm ecstatic to share that I've been offered an SDE intern position at Arcesium in my second year of Engineering, All thanks to youuuu !!!!

    • @mohamedsameer137
      @mohamedsameer137 ปีที่แล้ว +4

      Ur LinkedIn profile ?

    • @manrar8419
      @manrar8419 ปีที่แล้ว

      @@mohamedsameer137 search for Hriday Rathi, I'm from Plaksha University

    • @eshitaaaa
      @eshitaaaa ปีที่แล้ว

      Hey, I'm also in the same path looking for interns and following his sheet. Would you like to connect?

    • @AkshayGoel-of8ic
      @AkshayGoel-of8ic ปีที่แล้ว

      ​@@manrar8419for sde post, did you do other than the playlist, please tell me....

    • @infinity2creation551
      @infinity2creation551 11 หลายเดือนก่อน

      @@eshitaaaa whats your linkedin

  • @gunduboinadileep9523
    @gunduboinadileep9523 7 หลายเดือนก่อน +37

    understood!!.... at 22:30 low = 64 as low = mid+1 => low = 63+1 = 64 : )

  • @Codro09
    @Codro09 5 หลายเดือนก่อน +14

    I firstly watched the whole explanation till linear search then I was able to write the whole code by myself in binary search. Thank you striver

    • @VarshaSingh-hi2sb
      @VarshaSingh-hi2sb 20 วันที่ผ่านมา

      Sometimes the answer is at low & sometimes its at high so in which case its at low an which case at high ?

    • @kamaleshkumar167
      @kamaleshkumar167 2 วันที่ผ่านมา

      @@VarshaSingh-hi2sb true i am also facing the same problem i found a possible solution instead of returning high or low start off by saving your mid index in a ans variable and return it then you can understand if its the low that we are returning or the right

  • @Veer_Shiv
    @Veer_Shiv ปีที่แล้ว +118

    Watching the whole playlist is just like watching anime and waiting for upcoming episodes tooo 😝

    • @Lekshmi_sree
      @Lekshmi_sree ปีที่แล้ว +2

      Do you have solve DSA complex problem now?

    • @saketsoni2587
      @saketsoni2587 ปีที่แล้ว

      @@Lekshmi_sree yes i guess

    • @nikhilkumarjamwal5322
      @nikhilkumarjamwal5322 ปีที่แล้ว +4

      No manga here tho!🌝

    • @omkarshendge5438
      @omkarshendge5438 2 หลายเดือนก่อน +1

      do you go on just watching these videos without looking at the question first by yourself or do u first look at the question yourself and then watch this video?

  • @DEVANSHVYAS-z1b
    @DEVANSHVYAS-z1b 3 หลายเดือนก่อน +14

    17:30 There is a mistake in condition as (cntStud == m) will be true in this testcase but let pages[] = {25, 46, 28, 43, 50}. In this upto 70 pages, 5 students will be returned from second function but the moment 71 is checked no of student required will reduce to 3 as (25+46), (28+43), (50). And condition cntStud == m will reject it. Note that 71 is the maximum pages a student is allowed to take, so i can distribute (25+46), (28), (43), (50) to 4 students.
    Thus condition should be (cntStud

    • @dipingrover1970
      @dipingrover1970 3 หลายเดือนก่อน +2

      but bro book with 28 pages and 43 pages will be allocated to 2nd person only as maxlimit of pages is 71 how you distributed in 4 persons can you explain ?

    • @DEVANSHVYAS-z1b
      @DEVANSHVYAS-z1b 3 หลายเดือนก่อน

      @@dipingrover1970 71 is the "maximum limit" a student can hold. As number of students increase it becomes even more easy to distribute so that each of them is having lesser pages than the max limit.
      If I have 4 students, i can distribute in this way : (25+46) (28) (43) (50).

    • @Raza_Verse
      @Raza_Verse 3 หลายเดือนก่อน

      ​@@dipingrover1970 can your give output for arr- 21,32,45,25,78
      M=4
      The answer will be min pages so 53 but 78 coming how reply

    • @dipingrover1970
      @dipingrover1970 3 หลายเดือนก่อน

      @@Raza_Verse but bro if we take pages less than 78 then it is not possible for a student to take a book alone of 78 pages .

    • @VanshKalra_cpp
      @VanshKalra_cpp 2 หลายเดือนก่อน

      @@dipingrover1970 its simple lets take for eg arr=[1,2,3,4,7] and m=4 but acc to our algo 1st student will take 1+2+3 =6 pages then second will take 4 and 3rd will take 7 and we will never reach cnt of students==m==4 therefore condition should be cntstun return -1

  • @VineetKumar-fk2rl
    @VineetKumar-fk2rl 8 หลายเดือนก่อน +4

    Once you explained the logic I wrote the code all by myself for both brute and optimal it's because of your lecture my cognitive skill is increasing thanks a lot❤❤❤
    I

  • @secretvibz6300
    @secretvibz6300 4 หลายเดือนก่อน +3

    The way you got us to think why Binary Search -> was great !!! ...and this is actually what is to be taught in problem solving sessions. thank You very much Striver

  • @lakshayyadav9850
    @lakshayyadav9850 ปีที่แล้ว +6

    Respect++ for Raj bhaiya!!
    If i was not learning dsa in such a constructive way idk where would i have been!!
    I solved this question by my own all thanks to you for creating this playlist and i am following your AtoZ sheet its amazing!!!
    Thanks 🌟🌟🌟🌟✨✨

  • @vedfutane7995
    @vedfutane7995 ปีที่แล้ว +24

    Please don't change problem links of A-Z dsa sheet frequently recently all gfg link got replaced with code studio links. It breaks the flow for those who are already preparing from the sheet. Instead of replacing existing links with new link you can add new section for code studio links @takeUforward

    • @pratyushraj2629
      @pratyushraj2629 ปีที่แล้ว +8

      yes , you are right , i believe he is being sponsored by codestudio which is understandable but atleast we should get another set of problem on gfg alongside the others . I personally find that the gfg problems are a little more challenging and greater number of solutions are available , hence i choose gfg, what do u say?

    • @tanishtha-dj1wu
      @tanishtha-dj1wu ปีที่แล้ว

      hey i am facing the same problem.If you had made an excel for that,kindly share it @pratyushraj2629

  • @084abhigna_y8
    @084abhigna_y8 4 หลายเดือนก่อน +1

    No words to express my gratitude towards the man teaching here 😇

  • @harshith4549
    @harshith4549 3 หลายเดือนก่อน +4

    I have a slight correction in the brute force solution. The countStudent returned from the helper function can be less than or equal to number of students(m) given. (cntstu

    • @VarshaSingh-hi2sb
      @VarshaSingh-hi2sb 20 วันที่ผ่านมา +1

      We are doing high=mid-1 in else but that means that if (student

  • @HarshKumar-ip5nr
    @HarshKumar-ip5nr ปีที่แล้ว +4

    Can wait to get this playlist completed. Thanks for the free content.

  • @shankargowd9777
    @shankargowd9777 ปีที่แล้ว +17

    This problem is quite similar to "allocate minimum number of pages" and "painters partition" problems

  • @ujjawalraj6096
    @ujjawalraj6096 ปีที่แล้ว +21

    This is not an tough question if you are following this playlist this is an cakewalk
    Solve by own
    Tysm Understood everything❤

  • @arujain1690
    @arujain1690 8 หลายเดือนก่อน +2

    It is hard, one of the question i didn;t get even after reading it like 5 times. Nice explaination as always!

  • @VishalKumar-bj4nl
    @VishalKumar-bj4nl 2 หลายเดือนก่อน

    Thank you very much sir. I've Been stuck on this problem from the last 3-4 days,watched a lot of videos but your explanation is just on some different level.

  • @aswinbarath
    @aswinbarath 6 หลายเดือนก่อน

    You saved my day, Striver bro. I was struggling without the Dry Run of the problem. This video solution is very helpful to understand everything like the approaches using Linear search, Binary Search, the Time Complexity, Dry Run, Intuition and Psuedo code. Thank you so much, bro.

  • @techatnyc7320
    @techatnyc7320 8 วันที่ผ่านมา

    Loved the approach. Thanks Striver!

  • @devils9844
    @devils9844 ปีที่แล้ว +5

    Bhaiya I understand that you want to keep the course at a comfortable pace for better understanding, but i feel the frequencies of the videos should be increased as i think the course is moving too slow.
    Maybe its just me, but i thought that i would let you know. Thank you bhaiya for this amazing free course

    • @takeUforward
      @takeUforward  ปีที่แล้ว +12

      No it is not that, it's just that lately I have a lot of office work, which does not leaves me with much time, I am just too exhausted, and apart from some topics, almost all are done, so I am going at my pace.

    • @ambaradhikari7425
      @ambaradhikari7425 ปีที่แล้ว +2

      @@takeUforward bro linked list, string, stack, queue, heaps, bit manipulation these are the topics left, if not all the problems but atleast solve few important problems of all the topics.

    • @kshitijkumre9895
      @kshitijkumre9895 ปีที่แล้ว +2

      @@takeUforward Please don't change problem links of A-Z dsa sheet frequently recently all gfg link got replaced with code studio links. It breaks the flow for those who are already preparing from the sheet. Instead of replacing existing links with new link you can add new section for code studio links

  • @YNWA-q7y
    @YNWA-q7y ปีที่แล้ว +7

    Hi Raj, in this video at 22.28 we are choosing the right subarray , so we should take the mid as 64 (i.e mid=mid+1) and not 62 .Right??

  • @mhsunny123
    @mhsunny123 ปีที่แล้ว +3

    Exactly same question as LC 1011 : Capacity to Ship Packages within D Days

    • @tejaswaniguttula5961
      @tejaswaniguttula5961 5 หลายเดือนก่อน

      @mhsunny123
      Problem 1: Delivering packages (like in the shipping problem):
      You have a bunch of boxes (packages) to deliver.
      You have a truck with a certain weight limit (capacity).
      You can fit any number of boxes in the truck as long as the total weight doesn't go over the limit.
      Your goal is to find the smallest truck (capacity) that can deliver all the boxes in D days or less.
      Problem 2: Distributing books to students:
      You have a bunch of books to distribute to M students.
      Each student must get at least one book.
      You can't give half a book to a student, they need a whole one (contiguous block).
      Your goal is to find a way to distribute the books so that every student gets at least one book.
      Why the code checks differently:
      In the delivery problem: You're looking for the smallest truck that works. So, if you find a capacity that lets you deliver everything in D days or less, you know you can probably do even better with a smaller truck (hence checking numberOfDays

  • @cinime
    @cinime ปีที่แล้ว +2

    Understood! Super fantastic explanation as always, thank you so so much for your effort!!

  • @oyeesharme
    @oyeesharme หลายเดือนก่อน

    thanks bhaiya i have completed more than 80 questions in the last 3 weeks and it's really helping me in web dev also

  • @1tav0
    @1tav0 ปีที่แล้ว +2

    Yes!! thank you so so much for the dp and graphs series sir much love and gratitude from ca !

  • @ravindardeeti4364
    @ravindardeeti4364 20 วันที่ผ่านมา +1

    you are the beast at explanation man love you

  • @stith_pragya
    @stith_pragya 7 หลายเดือนก่อน +1

    UNDERSTOOD...Thank You So Much for this wonderful video..............🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻

  • @rohanpathak
    @rohanpathak ปีที่แล้ว +3

    Bhaiya thanku for the course, but kab tak complete hojaaega course??❤

  • @SuvamoySamanta-n2x
    @SuvamoySamanta-n2x 7 วันที่ผ่านมา

    When I saw this lactur my heart always say about more more lots of more slove questions

  • @fettuccine794
    @fettuccine794 ปีที่แล้ว +2

    Striver is GAWDDDDD man !!! I wish I hadn't wasted my time watching Kunal Kushwaha's videos.

    • @atharvameher5880
      @atharvameher5880 ปีที่แล้ว

      I am watching Kunals what do I do? Where did he go wrong?

    • @fettuccine794
      @fettuccine794 ปีที่แล้ว

      ​​@@atharvameher5880 his videos are good for theoritical understanding but not upto the mark for problem solving , you will not be able to evolve to leetcode medium and end up loads of just easy questions also his playlist is incomplete since 2 years . Watch Pepcoding and Strivers videos they are the best , I am able to solve Leetcode Mediums after watching them

    • @akworld2739
      @akworld2739 10 หลายเดือนก่อน +1

      @@fettuccine794 hi please can u tell me how u r practicing problems
      have u taken any dsa course i am unable to solve the new problems
      kuch easy to ban jate lekin mideum nhi ban pate hai bahi koi tips ho bata ho apne experience se
      i am in third year

    • @fettuccine794
      @fettuccine794 10 หลายเดือนก่อน

      @@akworld2739 watch the Binary Search playlist by Striver and try to solve them on your own....you can pretty much ace that.....after than if you are doing Java watch Pepcoding videos....watch topics like Hashmaps , Heaps , Priority Queues , Stack , Queues , you will find many Leetcode Medium problems Doable....after that try to Master Recursion which is the most important topic....Pepcoding (Level 1 and Level2) are two of the best Recursion playlist in the internet.....along with Recursion side by side start learning the little Basics of Dynamic programming(just basics) like Memoization.....if you have done enough practice of Recursion , complete LinkedList and Trees....these two are easy topics and are just applications of Recursion....you will be able to solve many Medium problems of these topics.....After all these comes the most important part - Graphs and Dynamic Programming.....for these topic Striver is the best in the internet....better than any other free or paid courses , nobody can beat him....I believe that one should give minimum 3-4 months to Master these topics ....I am also doing DP right now
      Hope this answer helps you !!

    • @fettuccine794
      @fettuccine794 3 หลายเดือนก่อน

      ​@@akworld2739, stop watching many tutorials, 1st try to do the problem for 30-40mins by yourself then watch the solution

  • @anish-acharya
    @anish-acharya ปีที่แล้ว +1

    This video is more understanding then code help's allocate books. Thanks

    • @AjithKumaR-jw9wt
      @AjithKumaR-jw9wt 10 หลายเดือนก่อน

      Hi, I have one doubt pls clarify, In linary search approach questions like this arr-8,9,10,50 student-3 in this how linear search works

    • @harshitpatil6138
      @harshitpatil6138 7 หลายเดือนก่อน +1

      Try to minimize your range .Your Range is from 8 to 50 Now you can easily apply linear search on it , and at last your ans will be 16
      @@AjithKumaR-jw9wt

    • @VivekKumar-kx2zf
      @VivekKumar-kx2zf 4 หลายเดือนก่อน

      @@harshitpatil6138 bro , i was also thinking the same . we should apply the binary search from lowest element to sum of array. but striver didn't recommend it.

    • @VivekKumar-kx2zf
      @VivekKumar-kx2zf 4 หลายเดือนก่อน

      @@harshitpatil6138 in that case 10 should be the answer🤔

  • @studynewthings1727
    @studynewthings1727 ปีที่แล้ว

    Hi Striver, I watched solution, linear Search wala part twice and I got the point. Thankyou So much.

  • @abdussalam-4836
    @abdussalam-4836 2 หลายเดือนก่อน

    after watching the whole playlist this question was easy for me

  • @Freefire-hp4zz
    @Freefire-hp4zz ปีที่แล้ว +1

    Waiting for STRING PROBLEM PLAYLIST STRIVER BHAI HOPE YOU WILL DO IT BEFORE MY PLACEMENT STARTS

  • @mrinalchoudhary7525
    @mrinalchoudhary7525 6 หลายเดือนก่อน

    Your explanation is insane. Hats off.

  • @footballcreativeeverywhere260
    @footballcreativeeverywhere260 ปีที่แล้ว +1

    What a tumbnail man !!! ❤️ , Just wow ....

  • @ishwamgarg
    @ishwamgarg ปีที่แล้ว

    Sir Your explanation is the best, And thanks to you today I was able to solve this problem by my own without seeing your solution code. 🙏🙏

  • @MJBZG
    @MJBZG 2 หลายเดือนก่อน +2

    could solve it myself, thanks!

  • @ai_jnab_420
    @ai_jnab_420 20 วันที่ผ่านมา

    understood 21:12 mid = (49+109)/2 = 79!

  • @NamanKumar-v7i
    @NamanKumar-v7i 3 หลายเดือนก่อน

    Thank you brother now I finally understand this kind of pattern

  • @shivarajpatil8699
    @shivarajpatil8699 ปีที่แล้ว +1

    Striver bhai i didn't understand how the opposite polarity will work in this question? both sides were not possilbe in beginning even the high side then how can we decide in these situtations? ik you said high was kind of possible but i don't think that was clear enough for me. if you could elaborate on that part it would be helpful. Thank you for this series btw! You're doing god's work.

    • @takeUforward
      @takeUforward  ปีที่แล้ว +4

      Hi, i have a question about part of the video with linear search. In that part if and only if helper function returns exactly same number as the number of students it will be satisfied, but if we check it for this test case:
      n = 4; m = 3;
      books = {24, 49, 24, 49}; The solution should be 73, but when the code gets to that point it will return 2, and so on... So 3 will never be returned; Based on this the array of returned values would look like 4, 4, ... 4, 2, 2, ...
      Did I miss something?
      Someone asked the same question, I gave the below answer
      So if its under, it means its possible. As you technically can go from 2 to 3 students by limiting some distribution, as you have no such barieer, but you cannot come back from 4 to 3. As you have a barrier :)

  • @sohampal1596
    @sohampal1596 ปีที่แล้ว +2

    hey striver please add the gfg links. I have solved many problems on gfg and suddenly it is removed from the A-Z SDE sheet. please give us a choice at least. now my progress is ruined.

  • @shivangkhandelwal334
    @shivangkhandelwal334 ปีที่แล้ว +2

    I was wondering if we can use sliding window for this problem and simply iterate the window of size (no. of books-no. of students +1) tracking the minimum sum of the elements in the window...Can we use this approach ????

    • @piyush29864
      @piyush29864 4 หลายเดือนก่อน

      it wont work. Window size can vary

  • @sanchitdeepsingh9663
    @sanchitdeepsingh9663 3 หลายเดือนก่อน

    these are the toughest ques on BS , there is also feel of CP in these ques

  • @devateja9045
    @devateja9045 ปีที่แล้ว

    Man, you are just awesome. More power to you

  • @niceguy3773
    @niceguy3773 ปีที่แล้ว +2

    Bro i am feeling a lot difficult in solving strings and heaps related problems could you please cover those as soon as possible...
    I know its difficult for you to manage but atleast can you tell me what i have to do to master these....

  • @kshitijkumre9895
    @kshitijkumre9895 ปีที่แล้ว +2

    Please, Do try to complete at least till Sliding Window (or) Heaps (Step:11) of A2Z DSA Course. Only 1 month is remaining for placements😔😶😶

  • @JayPatel-sn7it
    @JayPatel-sn7it ปีที่แล้ว +5

    Bhai please put back the GFG links instead of Coding Ninja in A2Z DSA
    Please.... CN is very boring platform to get solve our doubt and also less support of community.

  • @alamkhan6688
    @alamkhan6688 ปีที่แล้ว +3

    sir plz add gfg link in striver SDE A to Z sheet we are halfway done to it

  • @souvikbiswas284
    @souvikbiswas284 6 วันที่ผ่านมา

    Striver: This is an extremely hard question
    ME: Just changed the lower and upper limit and modified the conditions of previous question and the question is solved.
    😉😉. All Thanks to him though.

  • @Roshan__3006
    @Roshan__3006 5 หลายเดือนก่อน

    Danger bro, amazing my doubt is clear about is question Thank you for your videos.

  • @AtulKumar-c4x7l
    @AtulKumar-c4x7l ปีที่แล้ว

    understood
    Thank you striver for such an amazing explanation

  • @agnivashil4130
    @agnivashil4130 8 หลายเดือนก่อน +1

    22:26 the low should be mid+1 so 64 , isn't???

  • @ishangujarathi10
    @ishangujarathi10 ปีที่แล้ว

    lovedd the intuition!!
    understood completely!!!
    tysmm

  • @manavsingh5919
    @manavsingh5919 ปีที่แล้ว

    Thank you Striver Understood Everything🙂

  • @prakashsharma4899
    @prakashsharma4899 6 หลายเดือนก่อน

    Hi Raj, This method doesn't works for this test case if the array is [35, 25, 20, 30, 60] and m( no. of students) = 4 because according to this code it says there is no answer possible. But practically there are 3 ways we can divide these books to 'm' students
    35, 25 || 20 || 30 || 60
    35 || 25,20 ||30 || 60
    35 || 25 || 20, 30 || 60
    Could you please explain

  • @nirupamsuraj1634
    @nirupamsuraj1634 ปีที่แล้ว +2

    If anybody knows please tell which is the video that explains opposite polarity concept, thank you

  • @Sim_tim
    @Sim_tim ปีที่แล้ว +1

    Hey.... if possible could you please create a video regarding like ... number of other rounds and type of questions asked in those rounds, in product based interviews based on your experience...if possible, it would be helpful.
    Thankyou

  • @sangeeta35
    @sangeeta35 ปีที่แล้ว

    thank you for the wonderful explanation , i have a little doubt how we are assuring that low is equal to the sum of pages , becoz we are just changing it to mid+1 many times and mid is the average of high and low and there is no surety that mid+1 is equal to the sum elements of array

  • @PiyushKumar-xe1ng
    @PiyushKumar-xe1ng 2 หลายเดือนก่อน

    found it easier than aggressive cows , when you are able to conceptualise a question in your mind then it becomes easier to write it in a code

  • @abhayroadlines528
    @abhayroadlines528 9 หลายเดือนก่อน

    Thank you so much for this wonderful explanation♥

  • @hetpatel7399
    @hetpatel7399 ปีที่แล้ว

    Happy Guru Purnima teacher+bhaiya :)

  • @aayushmathur4229
    @aayushmathur4229 3 วันที่ผ่านมา

    at 22:46 mid = (49+109 )/2 = 158/2 = 79(not 78).

  • @aadharjain313
    @aadharjain313 11 หลายเดือนก่อน

    Hi raj , A small doubt.
    In the brute force approach , why did in the end when none of the possible values worked , we returned max_element of list and not -1. If max_element of list was a potential answer then it should have been taken care in the loop only.

  • @52_it_rohitmukherjee99
    @52_it_rohitmukherjee99 ปีที่แล้ว

    what an explanation ! clearly understood .

  • @VaishnavI-me8bz
    @VaishnavI-me8bz หลายเดือนก่อน

    Why one test case failing when i tried to implement the
    == ,

  • @tusharnanda744
    @tusharnanda744 ปีที่แล้ว

    understood ! completed 335 / 454 of A2Z all beacuse of striver . Thanks a lot

    • @eshitaaaa
      @eshitaaaa ปีที่แล้ว

      Hey, im on the same path, would you like to connect and share your coding journey?

    • @cp65143
      @cp65143 11 หลายเดือนก่อน

      How many days it takes generally

  • @sujalgupta6100
    @sujalgupta6100 4 หลายเดือนก่อน

    the condition check will be studentsRead

    • @Ekam873
      @Ekam873 2 หลายเดือนก่อน

      i also have same doubt

  • @sanchisingh481
    @sanchisingh481 ปีที่แล้ว

    you know i used the logic of aggresive cows that you had taught in that video and solved this question using a boolean check function , and the runtime beat 100% i know its not that big of a deal haha kabi kabi tukka lag jata hai but it feels good 😄

  • @adityarajvermaa
    @adityarajvermaa ปีที่แล้ว

    again even this one .....i coded by myself..thanks bhai

  • @mayankshakya9200
    @mayankshakya9200 ปีที่แล้ว

    Sir plz next episode plzzz
    And one question: ki next konsa topic cover karaoge after binary search ??? ❤❤❤❤

  • @artofwrick
    @artofwrick 6 หลายเดือนก่อน

    A god kind of explanation ❤❤

  • @suchitpatel8700
    @suchitpatel8700 หลายเดือนก่อน +1

    thanks striver 😄

  • @varungoyal3071
    @varungoyal3071 3 หลายเดือนก่อน

    Amazing explanation!!

  • @Shunya_Advait
    @Shunya_Advait ปีที่แล้ว

    Understood easily Sir, Thanks a lot .

    • @AjithKumaR-jw9wt
      @AjithKumaR-jw9wt 10 หลายเดือนก่อน

      Hi, I have one doubt pls clarify, In linary search approach questions like this arr-8,9,10,50 student-3 in this how linear search works

  • @shivangiagarwal5493
    @shivangiagarwal5493 2 หลายเดือนก่อน

    Can this problem be solve like this, you take (no_of_books - no_of_students)+1, let say that is 2, so maximum no of books a person can be assigned, now if we find sliding window of size 2 with minimum sum, can this problem be solved?

  • @ritwik121
    @ritwik121 ปีที่แล้ว

    What an explanation. Thanks striver.

    • @AjithKumaR-jw9wt
      @AjithKumaR-jw9wt 10 หลายเดือนก่อน

      Hi, I have one doubt pls clarify, In linary search approach questions like this arr-8,9,10,50 student-3 in this how linear search works

  • @rushidesai2836
    @rushidesai2836 3 หลายเดือนก่อน

    Had to watch it twice. One of the most intersting questions I have ever seen.

  • @abhijitkumarsinha
    @abhijitkumarsinha 15 ชั่วโมงที่ผ่านมา

    do we return low in case of (min)max and high in case of (max)min ?

  • @profesor6885
    @profesor6885 5 หลายเดือนก่อน

    Hi I have this small doubt ,
    12,34,67,90
    if we put this array in compiler , and compute for the helper function as given in solution, we would get answer to be 2 , shouldnt be 3 since the
    12,34 | 67 | 90 , would be the configuration ?

  • @NitinKumar-wm2dg
    @NitinKumar-wm2dg ปีที่แล้ว

    This is similar to shipping belt question from BS playlist, i solved it and then came here. Your approach helps in solving other question also. Thank you bhaiya.

  • @jesussenafernandes5112
    @jesussenafernandes5112 5 วันที่ผ่านมา

    You are amazing

  • @kaushiksen2190
    @kaushiksen2190 10 หลายเดือนก่อน +2

    Linear Search Code gives wrong answer for the testcase N = 7, A[ ] = [15, 10, 19, 10, 5, 18, 7]
    M = 5. Output should be 25 but the code gives output as -1. Range is from 19 to 84. From 19 to 24, at 17:24 , cntStu returns 6 as student output. When pages(i) = 25, cntStu returns 4, and note that it can also return 5 as ans so 25 becomes our output but after return 6 from 19 to 24, at 25 cntStu returns 4 and m = 5 is never satisfied.
    This is my code below,
    class Solution
    {
    int cntPages(int A[], int pages,int sizeArray)
    {
    long long student = 1, capacity = A[0];
    for(int i = 1; i < sizeArray; i++)
    {
    if(A[i] + capacity

    • @kaushiksen2190
      @kaushiksen2190 10 หลายเดือนก่อน +1

      Ok so it is if(cntStu

    • @sujalgupta6100
      @sujalgupta6100 4 หลายเดือนก่อน

      @@kaushiksen2190 the condition check will be studentsRead

  • @NamrathaSairam
    @NamrathaSairam 3 หลายเดือนก่อน

    When do we use the opposite polarity concept and when do we use the return mid concept, I am a little confused.

  • @shubhamsharma-nb8yd
    @shubhamsharma-nb8yd ปีที่แล้ว

    Can add another edge case - if( m == n ) return low;
    Adding this makes my code 100 percent efficient from 96.03
    :P Just small wins ..

  • @firebout7675
    @firebout7675 9 หลายเดือนก่อน +1

    understood

  • @siddharth892
    @siddharth892 8 หลายเดือนก่อน

    But what if the subsequences were allowed as in the allocation of books could be discontinuous.

  • @SYCOA12CHAITANYAASOLE
    @SYCOA12CHAITANYAASOLE 3 หลายเดือนก่อน

    Understood !! 😍😍

  • @NazeerBashaShaik
    @NazeerBashaShaik 5 หลายเดือนก่อน

    Understood, thank you.

  • @ambaradhikari7425
    @ambaradhikari7425 ปีที่แล้ว

    Bhaiya thank u for the solution, please complete within next 2months if possible placement season coming up, please bhaiya

  • @riteshbisht94
    @riteshbisht94 ปีที่แล้ว

    Stunning 🎉

  • @harshitpandey8304
    @harshitpandey8304 ปีที่แล้ว

    At 25:01, Why would you say that the high value (max pages = 172) is a possible answer?

    • @shreyas2030
      @shreyas2030 11 หลายเดือนก่อน

      add all the numbers in the array [ 25 + 46 + 28 + 49 + 24 ] u will get 172 as the sum.

  • @nishant8581
    @nishant8581 2 หลายเดือนก่อน

    Amazing video

  • @Raj-yr3vz
    @Raj-yr3vz ปีที่แล้ว +1

    it was asked in my PayPal OA

  • @noone-sb2dv
    @noone-sb2dv ปีที่แล้ว +3

    Hi, i have a question about part of the video with linear search. In that part if and only if helper function returns exactly same number as the number of students it will be satisfied, but if we check it for this test case:
    n = 4; m = 3;
    books = {24, 49, 24, 49}; The solution should be 73, but when the code gets to that point it will return 2, and so on... So 3 will never be returned; Based on this the array of returned values would look like 4, 4, ... 4, 2, 2, ...
    Did I miss something?

    • @noone-sb2dv
      @noone-sb2dv ปีที่แล้ว

      And how would this affect on binary search and proofing.

    • @takeUforward
      @takeUforward  ปีที่แล้ว +4

      So if its under, it means its possible. As you technically can go from 2 to 3, as you have no such barieer, but you cannot come back from 4 to 3. As you have a barrier :)

    • @noone-sb2dv
      @noone-sb2dv ปีที่แล้ว +1

      @@takeUforward Thanks brother. :D

    • @sayantanmanna1360
      @sayantanmanna1360 ปีที่แล้ว +3

      @@takeUforward Ha ha ha, I was struggling with this same issue since 4pm, and here I got my answer. Basically, even if we allocate books to less number of students for a particular value of 'mid' , that might be a possible answer as we can always reduce the number of *books* received by one student and allocate that to someone else (as 'mid' indicates the *maximum* number of *pages* to allocated per head, allowing us to allocate any number of pages less than 'mid') .
      Therefore, we are doing end=mid to preserve this value of mid , when the number of allocation is less than (or equal) the required value.

    • @AdityaKumar-be7hx
      @AdityaKumar-be7hx ปีที่แล้ว +2

      ​@@sayantanmanna1360 Is that why the correct way of using "ans" variable is
      This
      if(painters>k){
      low=mid+1;
      } else {
      ans=mid;
      high=mid-1;
      }
      And NOT (basically I thought we are trying to find first occurrence of k in a decreasing array :) )
      if(painters==k){
      ans=mid;
      high=mid-1; // we can have better answer on left
      } else if(painters>k){
      // we should increase the time to decrease the number of painters. Therefore go right
      low=mid+1;
      } else {
      high=mid-1;
      }

  • @daniarp8958
    @daniarp8958 ปีที่แล้ว

    One doubt, when to start count in helper function with 1 and when to start with 0 ?

  • @googleit2490
    @googleit2490 ปีที่แล้ว

    Understood, was enough difficult though!!

  • @YourCodeVerse
    @YourCodeVerse 8 หลายเดือนก่อน

    Understood✅🔥🔥

  • @VishalGupta-xw2rp
    @VishalGupta-xw2rp 11 หลายเดือนก่อน

    24:50 Opposite Polarity

  • @harshvardhansankpal716
    @harshvardhansankpal716 4 หลายเดือนก่อน

    sorry , but the brute force is very garbage soln. my soln: do arr.size( ) - ( no. of students - 1) this is the no. of books u have to form contigious subarrays and look for min. am i correct ?

  • @deepanshudahiya8966
    @deepanshudahiya8966 3 หลายเดือนก่อน

    coded it by myself just did one thing wrong i returned high instead of low