Allocate Minimum Number Of Pages

Поделиться
HTML-код
  • Опубликовано: 16 сен 2024
  • ALLOCATE MINIMUM NUMBER OF PAGES:
    Given number of pages in n different books and m students. The books are arranged in ascending order of number of pages. Every student is assigned to read some consecutive books. The task is to assign books in such a way that the maximum number of pages assigned to a student is minimum.
    Example :
    Input : pages[] = {12, 34, 67, 90}
    m = 2
    Output : 113
    Explanation:
    There are 2 number of students. Books can be distributed
    in following fashion :
    1) [12] and [34, 67, 90]
    Max number of pages is allocated to student
    2 with 34 + 67 + 90 = 191 pages
    2) [12, 34] and [67, 90]
    Max number of pages is allocated to student
    2 with 67 + 90 = 157 pages
    3) [12, 34, 67] and [90]
    Max number of pages is allocated to student
    1 with 12 + 34 + 67 = 113 pages
    Of the 3 cases, Option 3 has the minimum pages = 113.
    PROBLEM STATEMENT LINK:www.geeksforge...
    PLAYLIST LINK: • Binary Search | Interv... .
    ------------------------------------------------------------------------------------------
    Here are some of the gears that I use almost everyday:
    🖊️ : My Pen (Used in videos too): amzn.to/38fKSM1
    👨🏻‍💻 : My Apple Macbook pro: amzn.to/3w8iZh6
    💻 : My gaming laptop: amzn.to/3yjcn23
    📱 : My Ipad: amzn.to/39yEMGS
    ✏️ : My Apple Pencil: amzn.to/3kMnKYf
    🎧 : My Headphones: amzn.to/3kMOzM7
    💺 : My Chair: amzn.to/385weqR
    🛋 : My Table: amzn.to/3kMohtd
    ⏰ : My Clock: amzn.to/3slFUV3
    🙋🏻‍♀️ : My girlfriend: amzn.to/3M6zLDK ¯\_(ツ)_/¯
    PS: While having good gears help you perform efficiently, don’t get under the impression that they will make you successful without any hard work.

Комментарии • 528

  • @ashishchoksi8501
    @ashishchoksi8501 4 года назад +507

    Related Problems For Practice :
    Book Allocation Problem (GFG)
    Aggressive cow (spoj)
    Prata and roti (spoj)
    EKO (spoj)
    Google kickstart A Q-3 2020

    • @TheAdityaVerma
      @TheAdityaVerma  4 года назад +206

      + Painter Partition Problem

    • @shubhamchaudhary8688
      @shubhamchaudhary8688 4 года назад +255

      @@TheAdityaVerma + Below Leetcode Problems
      1482 Minimum Number of Days to Make m Bouquets
      1283 Find the Smallest Divisor Given a Threshold
      1231 Divide Chocolate
      1011 Capacity To Ship Packages In N Days
      875 Koko Eating Bananas
      Minimize
      774 Max Distance to Gas Station
      410 Split Array Largest Sum

    • @tastaslim
      @tastaslim 4 года назад +38

      @@shubhamchaudhary8688 Thanks a lot and @ashish choksi for mentioning related problems just because of you guys now I have good command at these types of problems

    • @sumitkumarverma313
      @sumitkumarverma313 4 года назад +4

      thanks

    • @prakharagarwal4933
      @prakharagarwal4933 4 года назад +3

      @@shubhamchaudhary8688 thanks it helped alot..

  • @Liftsandeats
    @Liftsandeats 3 года назад +35

    I like how he has never mentioned at the start/end of any video to like,subscribe,comment like everyone else does. Just pure meaningful content !!!

    • @divyareddy7622
      @divyareddy7622 Год назад +2

      i just needed help...what about if student is < k ? why is there no condition for that??

    • @vaibhavsingh8607
      @vaibhavsingh8607 Год назад

      @@divyareddy7622 I tried using
      return student == k ;
      which will return accordingly

    • @abinashdash7170
      @abinashdash7170 Год назад +1

      @@divyareddy7622 ​ Actually this condition should return "true" because if students < k that means we have distributed some extra books to a particular student, in that case we can take the extra book from that particular student and give it to a new student until the condition becomes students == k.
      This condition is already handled in isValid() function when we return true at the end of function.
      For example:- consider the following testcase:
      n = 7
      array = 15 10 19 10 5 18 7
      k = 5
      distribution for max = 25: [[15, 10], [19], [10, 5], [18, 7]] : no. of students == 4. But, we can easily take one book from a student and give it to a new student which will give us a no. of students == 5. In this case the function will return true.
      Thank You.

    • @saurabhkumarsrivastava6034
      @saurabhkumarsrivastava6034 Месяц назад

      ​@@divyareddy7622 you will not be in that case , start is the max element in the array , end is the sum , mid is the half of start +end ,you cant fill all the (sum of all pages ) to the mid , some pages(sum-mid) will go out of the capacity (mid) of first student . hope this helps XD:::

  • @rajshreegupta4454
    @rajshreegupta4454 3 года назад +25

    Can't believe we're getting such superb quality videos for free.

    • @divyareddy7622
      @divyareddy7622 Год назад

      i just needed help...what about if student is < k ? why is there no condition for that??

  • @035_shubhamsaurav5
    @035_shubhamsaurav5 4 года назад +23

    You give Best explanation available on RUclips..It's helping me a lot..

  • @paraschawla3757
    @paraschawla3757 3 года назад +72

    Give this guy a grammy for such an awesome explanation of one of the toughest questions :D
    I had a similar question asked int the Uber interview and I was blackout, literally impossible to solve this kind of question if you've not solved it before.
    Though I solved it using brute force - Recursion but that wasn't the expectation.
    This is a unique kind of pattern and I must say I learned a new pattern today. Though I strongly believe that such questions shouldn't be asked as it doesn't check your problem-solving skills.
    Awesome explanation, couldn't find anything better on the internet for this problem.

    • @hahahaha4217
      @hahahaha4217 Год назад

      I have a doubt why is there no condition for students

    • @vibhansh_bhatia
      @vibhansh_bhatia Год назад

      @@hahahaha4217 we divide the array into k parts so students cant be less than k, think of it this way.... you divide 100 in 3 equal halves, now you cant have 2 halves with both less than 33 and also add up to 100 as well.

    • @abinashdash7170
      @abinashdash7170 Год назад +2

      ​@@hahahaha4217 Actually this condition should return "true" because if students < k that means we have distributed some extra books to a particular student, in that case we can take the extra book from that particular student and give it to a new student until the condition becomes students == k.
      This condition is already handled in isValid() function when we return true at the end of function.
      For example:- consider the following testcase:
      n = 7
      array = 15 10 19 10 5 18 7
      k = 5
      distribution for max = 25: [[15, 10], [19], [10, 5], [18, 7]] : no. of students == 4. But, we can easily take one book from a student and give it to a new student which will give us a no. of students == 5. In this case the function will return true.
      Thank You.

  • @prakalpshakya1466
    @prakalpshakya1466 4 года назад +23

    Bhaiya, I have started CP and was struggling in implementation of Binary Search. I watched your full playlist and it really helped me a lot in implementing Binary Search. Thanks.

  • @lakshaydutta2299
    @lakshaydutta2299 4 года назад +5

    i just completed this playlist and once again want to thank you brother ! people usually consider binary search topic very easy and leave it, to all those reading this go ahead and watch this playlist from the start you guys wont be disappointed and will definately learn something new .Thank you Aditya bhai !

  • @Shivam-ln2yb
    @Shivam-ln2yb 4 года назад +100

    Just started with your dp videos it's amazing and best till date... Also request you to please make graph playlists. Eagerly waiting 😊

    • @pranav288
      @pranav288 2 года назад

      can i do dp before recursion ? If not please tell about a good recursion series (apart from take u forward). Thanks

    • @Jonathan-ng4vw
      @Jonathan-ng4vw 2 года назад

      @@pranav288 no

    • @sreenivasprasad6538
      @sreenivasprasad6538 2 года назад +1

      @@pranav288 Pepcoding Sumeet sir ke recursion videos. Top quality. And Doing DP without knowing recursion is waste and almost impossible.

    • @divyareddy7622
      @divyareddy7622 Год назад +1

      i just needed help...what about if student is < k ? why is there no condition for that??

  • @Khushboo1811
    @Khushboo1811 2 года назад +2

    This is the only channel where i understood this problem. Hats off and thanks for all your hardwork and efforts. You are a great teacher 👍

  • @karanrao8956
    @karanrao8956 Год назад +3

    This is the best explanation, I have ever seen. TYSM brother🙌❤

  • @Kundankumar-vh9qc
    @Kundankumar-vh9qc 4 года назад +19

    Hello Aditya,
    You are explaining very well. Please upload the next playlist ASAP and then keep adding the next videos. It would really help.

    • @divyareddy7622
      @divyareddy7622 Год назад

      i just needed help...what about if student is < k ? why is there no condition for that??

  • @dipendersingh1536
    @dipendersingh1536 2 года назад +14

    Sir i am literally crying right now because of two things 1.) I don't have a mentor or a teacher like you (but now we have you) 2.) Your simplicity level made me so so emotional Once again sir thank you so much : )

    • @divyareddy7622
      @divyareddy7622 Год назад +1

      i just needed help...what about if student is < k ? why is there no condition for that??

    • @codingfunda1813
      @codingfunda1813 Год назад

      ​@@divyareddy7622 there is one condition you need to allocate atleast 1 book to every student thats why number of student is not less than k

    • @prathamrajbhattnit-allahab4108
      @prathamrajbhattnit-allahab4108 Год назад

      @@divyareddy7622 k is itself number of students given

  • @agitatedenergy449
    @agitatedenergy449 4 года назад +29

    thank you so much for all the work you put into your videos, made tough topics like DP seem so simple.please upload more videos on important topics and questions from placement point of view, and maybe some tips and tricks also. You're like that friend who teaches imp topics 30 mins before the exam and all that only comes in the paper🔥🔥🔥 eagerly waiting for all the upcoming vids, i have notifications on!!

    • @TheAdityaVerma
      @TheAdityaVerma  4 года назад +13

      Thanks a lot for all that appreciation ✌️😅

    • @SandeepKumar-qw3tv
      @SandeepKumar-qw3tv 4 года назад +29

      ​@@TheAdityaVerma Men will be Men hahaha

    • @ecea044gauravgogoi2
      @ecea044gauravgogoi2 3 года назад

      @@SandeepKumar-qw3tv phirbhi sbse lamba creative comment yehi hain haha

    • @vishalbarvaliya2849
      @vishalbarvaliya2849 2 года назад

      @@SandeepKumar-qw3tv I saw that, he only replayed to women...😅😅😅😅😅😅

  • @vaibhavsethia70
    @vaibhavsethia70 4 года назад +4

    Amazing Explanation!
    I had spent 11 days thinking and trying to solve but you explanation was extremely clear.

  • @sourabhbagrecha
    @sourabhbagrecha 3 года назад +4

    As mentioned in the start "this is going to be the best question so far", indeed it was, and the explanation was just as amazing as the question, thanks Aditya.

    • @divyareddy7622
      @divyareddy7622 Год назад

      i just needed help...what about if student is < k ? why is there no condition for that??

  • @gaurabdas1510
    @gaurabdas1510 3 года назад +3

    Lecture 41 mins ka hai lekin feel nahi hua ki bohut lamba hai jab sunn raha tha. Upar se concept barhiya se samaj aa gaya. Thank you aditya bhaiya! ✌

  • @shahbazzeb6974
    @shahbazzeb6974 3 года назад +2

    Really cross through the best teacher all over you tube ....the way you teaches is like making most difficult question as cup of tea for us ....thanks a lot ❤️

  • @priyanshkumar17
    @priyanshkumar17 11 месяцев назад +1

    14:04 --> as per the given condition, no student can be left idle, so the start index should be bigger than 0 & the end index would be lesser than 100. To assign a student with a book, minimum one book is to be given for sure. Maximum pages he/she will read = max(arr) ...

    • @KUSHAGRA2807singh
      @KUSHAGRA2807singh 8 месяцев назад

      right because if arr[]={10,60};
      in this case mid ==35;
      and isValid function returrn true ; //which is not acceptable.

  • @player-te8tf
    @player-te8tf 2 года назад +2

    C++ Code for those who got stuck, yea if u did got stuck, go get some hands on other stuffs coding is really not for u , aditya wrote every code on a paper but still u got stuck : (
    class Solution
    {
    public:
    bool isValid(int arr[],int mid,int n, int m){
    int student=1;
    int sum=0;
    for(int i=0;imid){
    student++;
    sum=arr[i];
    }
    if(student>m) return 0;
    }
    return 1;
    }
    //Function to find minimum number of pages.
    int findPages(int A[], int N, int M)
    {
    //code here
    if(N

    • @crosswalker45
      @crosswalker45 Год назад

      for further optimising the code.. we have to initialize the start pointer to min of the array right? But in the video he has initialized the start pointer to max of the array ,i.e 40

  • @dishantpatel1278
    @dishantpatel1278 4 года назад +3

    i buy online course but i understand better here...best explanation ever.. thank you

  • @NitishKumarTutorials
    @NitishKumarTutorials 2 года назад +1

    how are we ensuring that each student is getting at least one book ?
    which logic is taking care of that part ?
    we are checking student > k , return false , what if student < k at end ??

    • @ashwinbhargava3011
      @ashwinbhargava3011 2 года назад

      did you find the answer for that ?

    • @NitishKumarTutorials
      @NitishKumarTutorials 2 года назад

      @@ashwinbhargava3011 I have seen this comment somewhere
      Not tried yet , check if it works out for you
      " I feel like. Since in the isValid function we check for k==M and for k

  • @yashgupta-rg5it
    @yashgupta-rg5it 4 года назад +12

    Very nice video bhaiya!!!!!
    For reference:
    #include
    using namespace std;
    bool valid(int arr[], int n,int s, int max){
    int students=1;
    int sum=0;
    for (int i = 0; i < n; ++i)
    {
    sum=arr[i]+sum;
    if (sum>max)
    {
    students++;
    sum=arr[i];
    }
    }
    if (students>s)
    {
    return false;
    }
    else
    return true;
    }
    int binarySearch(int arr[],int n, int s){
    int result=-1;
    // if books is less than students
    if(n

    • @divyareddy7622
      @divyareddy7622 Год назад +2

      i just needed help...what if students is < k ? why is there no condition for that??

    • @avgspacelover
      @avgspacelover Год назад

      @@divyareddy7622 watch take u forward video on the same question

    • @Amansingh-gi3gx
      @Amansingh-gi3gx Год назад

      @@divyareddy7622 do you get ans?

    • @manojpallakki8942
      @manojpallakki8942 8 месяцев назад

      No​@@Amansingh-gi3gx

  • @bhavyapandey
    @bhavyapandey 2 года назад +1

    If youtube had a love react, every video of yours would get that from me !!!!
    Flawless!
    As someone who likes teaching, I really look up to you :)

  • @dhruvagarwal646
    @dhruvagarwal646 3 года назад +47

    Even though your Binary Search playlist is sorted in quality of conceptual knowledge,
    Yet we can't jump to either half of your playlist 😅😅

  • @kailashjangir1530
    @kailashjangir1530 3 года назад +7

    completed this series in two days, really amazing ❤❤

    • @nikhild.20
      @nikhild.20 2 года назад

      same here... completed today in two days!!!!

  • @shashanksaurabh6478
    @shashanksaurabh6478 Год назад +2

    started on 14/7/23,5a.m. and was able to complete this masterpiece series successfully at 15/7/23,3:50 a.m., Grateful for this series.❤💙

  • @anubhavgupta2224
    @anubhavgupta2224 4 года назад +25

    Sir please backtracking k upar bhi ek playlist upload kr dijiye as it would be very helpful for students whose placement session is approaching

  • @shashijaiswal5014
    @shashijaiswal5014 2 года назад +2

    Completed this played in 2 days... It took 6-7 hr approx. To complete it. Thank you so much for creating such a great content. 😀

  • @mystryb345
    @mystryb345 4 года назад +2

    Finally finished this..Eageraly waiting for other playlist..Your every playlist is very helpful..thanks a lot

  • @vishwashdwivedi9469
    @vishwashdwivedi9469 3 года назад +6

    It won't give the correct output in the case ,
    n=5
    arr[] = 51 151 227 163 55
    m=3
    Correct output : 227
    Output from this code : 257
    @Aditya Verma Sir please pin this comment so that others can correct it !
    In isValid function we need to mention one more condition inside for loop i.e.
    if(arr[i]>mx)
    return false;
    , because as soon as any individual element's value gets greater than our threshold value mxs it is not possible that maximum sum of any subarray is less than or equal to mxs.

    • @AyushRawat-gr6ow
      @AyushRawat-gr6ow 3 года назад

      You are right , i added this statement in isvalid() part and the solution was accepted

    • @bishnoi6409
      @bishnoi6409 2 года назад +1

      bro that's why we take start = max element in the array.

    • @hahahaha4217
      @hahahaha4217 Год назад

      But why should u add that condition it will anyway return false once student goes above the value of k right...? Can u please explain y it is necessary to add that condition

  • @danishakhtar2683
    @danishakhtar2683 3 года назад

    love the way you treat the code ! never get such amazing content in free. lots of Love from NITW

  • @chandanbharti5207
    @chandanbharti5207 Год назад

    Finished the playlist and literally I am feeling confident now in BS...Thanks a lot, buddy :).The best thing is ki by solving and watching you how you tackle the problem it created an automatic process ki haan aisa hai to maybe we can apply that..

  • @vakhariyajay315
    @vakhariyajay315 Год назад +1

    Thank you very much.

  • @banditsumo4381
    @banditsumo4381 3 года назад +2

    Bhai bhut mast padhte ho tum bhagwan tumhe kamyabi ki nayi uchaio p le jaye

  • @priya_kumari7893
    @priya_kumari7893 3 года назад

    bestest and simplest explanation of this tough problem on the internet, thank you so much, sir!

  • @rishabhdwivedi5217
    @rishabhdwivedi5217 2 года назад +1

    "To me to fan hu, tum bhi ban jao.. Thankyou" Best line bhaiya, we are already your fan.

  • @itsamritanshu7
    @itsamritanshu7 4 года назад +1

    Thank you from bottom of my heart. These videos are very helpful.
    Eagerly waiting for your upcoming videos.

  • @Shenkeyful
    @Shenkeyful 4 года назад +10

    Hi Aditya... Your tutorials are awesome!! ... Could you please share the list of problems if you have handy which are similar to this "Allocate Minimum Number of Pages" problem concept?

  • @harshsingh357
    @harshsingh357 2 месяца назад

    Loved the explanation probably one of the best :)

  • @Gauravraj1098
    @Gauravraj1098 2 года назад +1

    great explanation , i came here after watching lots of videos on the same topic but nobody explained better than you. Hats of to you bro , ur channel is so underrated but I wish all ur hard work and skills will be much valuable in future.

    • @divyareddy7622
      @divyareddy7622 Год назад

      i just needed help...what about if student is < k ? why is there no condition for that??

    • @rohitramteke5951
      @rohitramteke5951 Год назад

      @@divyareddy7622 'K' is the number of students. array indexes represent the book numbers and value of arr[i] represent the number of pages in it the array of any particular book.

  • @shikhajadon175
    @shikhajadon175 4 года назад +6

    awesome video,
    I tried this question before,but i didn't understand it.
    but youuuu explained it so deeply that now i understood it very well.
    Sach me aap to CODING KE BAAP h.
    coding krna to koi aap se seekhe

    • @TheAdityaVerma
      @TheAdityaVerma  4 года назад +3

      Thanks Shikha !! 😅😅I hope that you wont forget it now and could do it the next time when you get across a question like this.

    • @shikhajadon175
      @shikhajadon175 4 года назад

      Sure I will never forget it

    • @anonymous-kl1un
      @anonymous-kl1un 4 года назад +1

      @@TheAdityaVerma bhaijaan batado ab ki iss mahine kuch aaega ki nahi. Roz roz ka intezar maare jaa rha hai merko

  • @deepakgurjar3746
    @deepakgurjar3746 2 года назад +1

    Learning the Best from THE Best

  • @AmandeepSingh-uq3wp
    @AmandeepSingh-uq3wp 2 года назад +21

    After finishing this playlist, I am just thinking🤔 why you stoped teaching a year ago? Being such a great teacher you should start making videos on other topics also as it will help students in their journey of learning DSA.

    • @divyareddy7622
      @divyareddy7622 Год назад +1

      i just needed help...what about if student is < k ? why is there no condition for that??

    • @usmanaliansari5223
      @usmanaliansari5223 Год назад

      @@divyareddy7622 that means there is less Books are present in the array as number of Students or one book in the list which not possible to distribute in both student i.e. -1.

    • @hahahaha4217
      @hahahaha4217 Год назад

      ​@@divyareddy7622 I have the same doubt

  • @anmolsinghal484
    @anmolsinghal484 3 года назад +28

    "Tu khel jaake maje kar" 🤣🤣🤣🤣🤣🤣

  • @sanidhyagupta1906
    @sanidhyagupta1906 4 года назад +7

    Sir, really really thanks for these awesome videos. I was initially struggling with binary search , but your playlist helped me a lot. Please make videos on graph theory and other imp topics.
    And phir se Sir, really really thanks🤘

  • @phlox22
    @phlox22 Год назад

    puri series dekhi kuch samajh nai aaya y question lekin ek bar m hi samajh aagya ,thanks a lot sir

  • @purandarparitosh
    @purandarparitosh 4 года назад +1

    Bhai, at this moment, I have seen all videos of yours. I can't thank you enough. You are brilliant. 🙏🙏🙏🙏 You are a blessing. 🙏🙏
    Please upload videos on RECURSION and BACKTRACKING. Please. 🙏🙏🙏🙏🙏

  • @yashkhatwani3198
    @yashkhatwani3198 2 года назад +1

    Bhai bohot sahi explaination

  • @AnojKumar-mu8be
    @AnojKumar-mu8be 4 года назад +6

    Hi Aditya, Kindly include problem "Median of two sorted array" in your binary search playlist. This question most frequently asked by companies.

  • @brijeshsharma216
    @brijeshsharma216 4 года назад +1

    awesome great mind blowing faad pelu zabardast aur kya bolu bhai abhi itna hi aa rha dimag me .. aur aayega to phir likh dunga

  • @ADITYASHARMA-dn1si
    @ADITYASHARMA-dn1si 3 года назад

    bro i was totally confused before looking to your video
    you just nailed it thumbs up man.
    subscriber++;

  • @devanshuchicholikar4091
    @devanshuchicholikar4091 3 года назад

    Bro You are Awesome! Raat ke 1 baj rahe hai but apke videos dekhke kabhi bore nahi hua hu. Aur padhne ka mann karta hai. Great series man! Keep up the good work.

  • @SupremeSid
    @SupremeSid 7 месяцев назад

    Perfect explanation. Far Better than others!!

  • @amijugjug
    @amijugjug 3 года назад +1

    Watched every video of this series and I could say that after your explanation and observation phase of the problem I was able to write whole damm code by myself I am really thankful to you coding was never that much easy until youtube recommendation introduce you to me. Thanks Aditya for make coding easy for us.

  • @yashkhatwani3198
    @yashkhatwani3198 2 года назад +1

    Ok so for any one who started with low=0 instead of low = max element in array. Just check one more condition iside valid functions for loop i.e if(A[i] > mid) return false; because there can be a scenario when m elements are there but last one is greater then our limit. Or the best thing is to take low = max element in array

  • @codedByAyush
    @codedByAyush 3 месяца назад

    Thanks a lot bhaiya for such a lovely & simple explanation

  • @RaviShankar-hu6yw
    @RaviShankar-hu6yw 2 года назад

    what is most fascinating about his explanation is that you are able to code by yourself before the video arrives at its mid .
    i mean who needs the code? when concept is crystal clear .

  • @abdussamad0348
    @abdussamad0348 2 года назад +2

    I liked the video in the first half, after watching code, I wanted to like it again.😂😂

  • @visheshagrawal8676
    @visheshagrawal8676 Год назад

    made so easy the concept of binary search on answer he is a gem guy

  • @vinothkumar-ek2rw
    @vinothkumar-ek2rw 3 месяца назад

    Thanks, Aditya. One of the best videos to learn BS.

  • @RitikSharma-pc5yj
    @RitikSharma-pc5yj 4 года назад +1

    Thank-you so much...this application of binary search is very very useful and being used in many areas if we look very closely...I'm shocked even it is used in "Ugly numbers III" and is far better than DP :>

  • @harshtyagi700
    @harshtyagi700 3 года назад +3

    One thing to note here is that in isValid function we're simply putting the array values without even checking that even an individual book may contain pages greater than maxPages passed into the function so we have to take that case into consideration while writing code otherwise it will simply call the statements inside if block and count will get increased and in the next iteration value stored in sum(or books) will be replaced by any other value .
    bool isValid(int maxPages,int *A,int N,int M)
    {
    int count=1,books=0;
    for(int i=0;imaxPages)
    {
    books=A[i];
    count++;
    if(count>M)
    return false;
    }

    }
    return true;
    // (count

    • @uptonogood300
      @uptonogood300 3 года назад

      GFG test cases are too weak i did it without taking the above point in consideration and it still passed but while doing painters partition problem on interview bit i had too add this condn to just pass the sample case !

    • @Amansingh-gi3gx
      @Amansingh-gi3gx Год назад

      Hello r u here I have one doubt..

  • @abhigyannayak4151
    @abhigyannayak4151 3 года назад

    The optimization that you told regarding setting low to max fo array is required..if someone starts if from 0 ro min of array, isValid function will fail for lower ranges, hence giving wrong output..
    anyway lower range, wont be having the answer.. hence, set it to max of array to make the isValid function work correctly.
    To understand it better take a small case of 5 in the same input, isValid function will pass the value and will give wrong output.
    Hence, its mandatory to set it to max of array

  • @kunalsharma735
    @kunalsharma735 4 года назад +1

    Thinking directly about this approach may not be possible in an Interview. We would start with simple recursive solution and then optimizing the solution we may end up with the Binary Search on Answer solution. So a recursive solution for the problem is,
    def solve(A, B):
    def helper(curr_val, n, students):
    if n == 0:
    if students == 0:
    return curr_val
    else:
    return float('inf')
    if students == 0:
    return helper(curr_val+A[n-1], n-1, students)
    else:
    same_student = helper(curr_val + A[n - 1], n - 1, students)
    different_student = helper(A[n - 1], n - 1, students-1)
    return max(curr_val, min(same_student, different_student))
    # just some base cases
    if not A or B > len(A):
    return -1
    elif B == len(A):
    return max(A)
    elif B

  • @GauravKumar-dw2ml
    @GauravKumar-dw2ml 2 года назад

    one condn is left in isValid func ------> if(a[i]>mid) return false ; else kuch case me ans galat aa rha h. Thankyou for this awesome explanation.

  • @Everything.corner
    @Everything.corner 4 года назад +5

    aditya please clarify!!!!!!!!
    if (student

    • @tushar5426
      @tushar5426 3 года назад +1

      I also have the same thought. There should be a separate condition.

    • @dhruvagarwal646
      @dhruvagarwal646 3 года назад

      The condition discussed in the video is right
      For ex: ar = [1,2,3,4,5,6,7,8,9,10], k = 5
      mid = 32 -> k = 2
      Suppose the return condition is return student == k
      So in this, it will return false and hence lo = mid + 1 = 33 (with increasing lo, students will become less)
      But in contradiction we need to minimise the total stress(pages to read) without violating the first constraint
      So the condition return student

  • @inclinedscorpio
    @inclinedscorpio 2 года назад +2

    Another explanation (for logic building): We need to reduce the maximum books allocated so that its minimum among all the permutation.
    The logic for this is: Allocate ~maximum number of books possible to all the students. - Think about it, you are trying to allocate as much books as possible to each students - (which is equivalent to reducing the maximum value).

  • @subhajitdutta5216
    @subhajitdutta5216 4 года назад +44

    Bhaiya please backtracking aur recursion ka playlist de dijiye😢🙏

    • @TheAdityaVerma
      @TheAdityaVerma  4 года назад +35

      Brother, it will be out before placements gonna start.

    • @anonymouscoder3238
      @anonymouscoder3238 4 года назад +3

      Bhaiya, please share these topics as soon as possible..due to Covid, my internship is going on right now and my ppo interview will be in June mid..
      I would be grateful if you could share it earlier than planned.. so that students like me can benefit too..
      Thanks a lot Bhaiya
      PS - Bhaiya you are a blessing for people like me! Thank you for this initiative!

    • @anonymous-kl1un
      @anonymous-kl1un 4 года назад +5

      @@TheAdityaVerma bhai jaan iss mahine kuch aaega hai kya?

    • @anonymous-kl1un
      @anonymous-kl1un 4 года назад +1

      @@TheAdityaVerma liar

    • @vivekgopalasetty2790
      @vivekgopalasetty2790 4 года назад

      @@TheAdityaVerma start ho gaya he please upload rest of the DP and graphs specially

  • @vedantagarwal22
    @vedantagarwal22 3 года назад

    Thanks for the wonderful explanations and videos !!

  • @jahnavigurdasani8005
    @jahnavigurdasani8005 3 года назад +3

    Please make a playlist on dfs and bfs related questions. Thanks alot for all the help!

  • @uptonogood300
    @uptonogood300 3 года назад

    bhai best !! watched this vid once and solved all the problems in pinned comment in one go .

  • @mlkgpta2869
    @mlkgpta2869 Год назад

    Maaza aaya
    aur ye maaza mai mere saath waalo aur juniors ke saath bhi batunga....

  • @039saranshvashisht8
    @039saranshvashisht8 2 года назад

    And thanks to you I am finally able to prepare my binary search properly

  • @AlbertoRodriguez-oe6jo
    @AlbertoRodriguez-oe6jo 2 года назад

    You're an exceptional teacher.

  • @harshlimbachiya7510
    @harshlimbachiya7510 2 месяца назад

    love you sir kya samjhaya hai sir apne ye sum❣❣

  • @SHASHIKUMAR-pp4hg
    @SHASHIKUMAR-pp4hg 4 года назад +2

    great explanation,I think we can optimize isvalid function to O(log(n)) from O(n).like we can store array sum as sum upto this element and find range for first student.then find range in right section in sum array for S2.little complicated!!!!

  • @amanraj3646
    @amanraj3646 4 года назад +2

    Bro please keep making videos they are really very helpful

  • @croxzoxcreation2555
    @croxzoxcreation2555 Год назад

    my friend suggested your chanell and now i will show i am happy with your vedio now you won new subcriber as me😊😊.. but bhya i noticed it's about a year you dont even post single vedio....please dont leave youtube😥😥...please keep sharing this tricks for 2-3 year student like us....

  • @zachrunner4490
    @zachrunner4490 2 года назад +3

    if let's say, in the isValid() function students count is less than k , should we not return False then? as we need count to be k.

  • @aaqib605
    @aaqib605 Год назад

    Thanks a lot.
    Best explanation. Keep up the good work.

  • @AnkitGupta-vo1kb
    @AnkitGupta-vo1kb Год назад

    Best Playlist For Binary Search

  • @himu2000
    @himu2000 2 года назад

    Thank you Sir, Very helpful tutorial, Love from Bangladesh.

  • @viggicodes
    @viggicodes Год назад

    One small point . one edge is missing . in the array if any element is greater than mid then isValid should return false but currently its returning true
    def isValid(self,A, n, k, mid):
    students = 1
    sum_ = 0
    for i in range(n):
    # one book can have max pages more than mid
    if A[i] > mid:
    return False
    sum_ += A[i]
    if sum_ > mid:
    students+=1
    sum_ = A[i]
    return False if students > k else True

  • @TOMGAMING-hy9hi
    @TOMGAMING-hy9hi 2 года назад

    "students ka stress reduce karna hai " bus yahi ek line thi jiski vajah se me pura algorithm proper samaj paya

  • @aditkalyani7966
    @aditkalyani7966 4 года назад

    Thank you brother, you explained it so nicely. Looking forward for your next videos

  • @shantanusharma184
    @shantanusharma184 2 года назад

    Very Nicely explained. Thank You for this amazing video

  • @praveenkumar-er6ze
    @praveenkumar-er6ze Год назад

    thanks aditya bhaiya to make understandable that problem ,
    i was not understanding on other channels

  • @myview9553
    @myview9553 3 года назад

    you explained this in the best way...
    keep it up!!!👍👍

  • @gauravvishwakarma7840
    @gauravvishwakarma7840 Год назад

    very goooood,,,vaaaaaaaaaaaaaaahhh bro.

  • @mohitmotwani9256
    @mohitmotwani9256 3 года назад

    Thank you for this amazing series. ♥♥♥

  • @sharuk3545
    @sharuk3545 3 года назад

    static boolean isValid(int arr[],int n,int m,int pages)
    {
    int s=1;
    int sum=0;
    for(int i=0;ipages) return false; // this case missing in vdio without this case your code will not submited
    sum=sum+arr[i];
    if(sum>pages)
    {
    s++;
    sum=arr[i];
    if(s>m) return false;
    }

    }
    return true;
    }
    thnks for explanation ,it is great

  • @tusharrohilla9344
    @tusharrohilla9344 4 года назад +2

    GFG Accepted Code::
    bool isvalid(long arr[], long n, long k, long mid)
    {
    long long stud = 1;
    long long sum = 0;
    for (long i = 0; i < n; i++)
    {
    sum += arr[i];
    if (sum > mid)
    {
    stud++;
    sum = arr[i];
    }
    if (stud > k)
    return false;
    }
    return true;
    }
    long long alloc(long arr[], long n, long k)
    {
    long long s = *max_element(arr, arr + n);
    long long e = 0;
    for (long i = 0; i < n; i++)
    e += arr[i];
    long res = -1;
    if (n < k)
    return -1;
    while (s

  • @praveenmani5672
    @praveenmani5672 3 года назад +1

    Thnx a lot bhia..... please keep making more such videos....

  • @__priyanshu__sharma____
    @__priyanshu__sharma____ Год назад +1

    where is the fault in this for the test case when arr= {1 17 14 9 15 9 14 }, no of student=7, size of arr=7;
    Please correct the fault;
    bool isValid(vector &arr, int size, int nofStudent, int mid){
    int studentCount=1;
    int sum=0;
    for(int i=0; imid){
    sum=arr[i];
    studentCount++;
    }
    if(studentCount>nofStudent){
    return false;
    }
    }
    return true;
    }
    int findPages(vector& arr, int n, int m) {

    if(m>n) return -1;
    int sum=0;
    for (int i : arr) {
    sum += i;
    }
    int start=0, end=sum, mid= start+(end-start)/2;
    int ans=-1;
    while(start

  • @tushargupta5805
    @tushargupta5805 3 года назад

    Wow sir salute to you aggressive cows waala question 1st try m bn gaya.
    sem 1 m diya tha humare teacher ne tb ghanta samajh ni aaya tha but aaj ye question dekh kr us question ki yaad aa gaya aur try krte hi ho gaya ❤❤❤

  • @thefizzshow
    @thefizzshow 2 года назад

    Binary Search Completed...Thank You Aditya Bhaiya💌

  • @nishantsagar5149
    @nishantsagar5149 3 года назад +2

    Here is my code for the same:
    class Solution
    {
    public:
    //Function to find minimum number of pages.
    bool is_valid(int* arr, int n, int m, int mid){
    int count = 1;
    int sum = 0;
    for (int i = 0; i mid){
    count++;
    sum = arr[i];
    }
    if (count > m) return false;
    }
    return true;
    }
    int findPages(int arr[], int n, int m)
    {
    //code here
    int start = *max_element(arr, arr + n);
    int end = accumulate(arr, arr+n, 0);
    int res = -1;
    while (end >= start){
    int mid = start + (end - start)/2;
    if (is_valid(arr, n, m, mid) == true){
    res = mid;
    end = mid - 1;
    }
    else start = mid + 1;
    }
    return res;
    }
    };

  • @vikashkumarchaurasia1299
    @vikashkumarchaurasia1299 4 года назад

    Amazing tutorial, Thanks brother!!!

  • @dishalekurwale5412
    @dishalekurwale5412 4 года назад +3

    Can you share the list of projects that you have implemented? what is the weightage of projects for selection process?
    Amazing playlists!

  • @edge123276
    @edge123276 2 года назад +1

    At 15:56 ,if the one student gets 40 number of pages ,then another students will get 60 ,then why the maximum number of pages will be 100 ,i didnt get?