Chocolate Distribution problem | Q30 | Love Babbar DSA Sheet

Sdílet
Vložit
  • čas přidán 9. 07. 2024
  • #competitiveprogramming #dsasheet #interviewpreparation
    In this video I have solved the 30th problem of the sheet i.e. Chocolate Distribution problem.
    String question Playlist = • Love Babbar DSA 450 Qu...
    Array question Playlist = • Love Babbar DSA 450 Qu...
    Love Babbar DSA Sheet : drive.google.com/file/d/1FMdN...
    Hope you like it. Comment if you have any doubt.
    LIKE | SHARE | SUBSCRIBE

Komentáře • 43

  • @sumitsingh-dk3zt
    @sumitsingh-dk3zt Před 3 lety +6

    Can we solve this problem in the time complexity of O(n) ?

  • @codeawezpassion7022
    @codeawezpassion7022 Před 2 lety +3

    maaza aa gayi ... you made the code explaination so easy .Thanku sir

  • @abhishekkumargupta3605
    @abhishekkumargupta3605 Před 3 lety +15

    why are u taking i+m-1

    • @shashankgaur3917
      @shashankgaur3917 Před rokem

      A window is of size m , so the last(max) element of window is at position i+m-1 , and we substract max-min in each window

  • @saharanaryan
    @saharanaryan Před 2 lety +2

    how did you clear the driver code ?

  • @sushantgupta4757
    @sushantgupta4757 Před 2 lety

    thanku so much bhaiya

  • @saharamanson1970
    @saharamanson1970 Před 3 lety +1

    Awesome Bro Keep it Up..................................

  • @siddhantyadav4531
    @siddhantyadav4531 Před 2 lety

    Awesome 👌👌👌👍👍👌

  • @SharuxD
    @SharuxD Před 2 lety +3

    I dont get it how they classified this as easy problem

  • @shikharchoudhary7639
    @shikharchoudhary7639 Před měsícem

    how did you know in yoiur mind that it will be i+m-1 ?? Why not consider something else ?

  • @sahdevsingh8858
    @sahdevsingh8858 Před rokem +1

    Sir, how the time complexity is O[nlogn] in your case?

  • @fffooccc9801
    @fffooccc9801 Před 11 měsíci

    i am not getting correct answer in this approach by simple pick and non pick please help:
    long long solve(int index,int current_q,int t_q,vector &input,long long mmin,long long mmax){
    if(index >=input.size()) return INT_MAX; //toal elents le nhi paya answer nhi nikal payega

    if(current_q==t_q) { //total reach ho gya
    return abs(mmin-mmax);
    }

    for(int i=index+1;immax){
    newmax=input[i];
    }
    if(input[i]

  • @kshitiztripathi7623
    @kshitiztripathi7623 Před 3 lety +1

    Can u tell what is the reason to do sorting first?

    • @CodeLibrary
      @CodeLibrary  Před 3 lety +1

      We are using greedy approach, so by sorting for each window we get min element in 1st index of window and max element in last index of window

  • @shivaygupta9837
    @shivaygupta9837 Před 3 lety +1

    why we are sorting the array.Can you please brief this approach

    • @CodeLibrary
      @CodeLibrary  Před 3 lety +1

      We are using greedy approach, so by sorting for each window we get min element in 1st index of window and max element in last index of window

  • @amishaverma4097
    @amishaverma4097 Před 3 lety +1

    Nice explanation but when I initialise min with INT_MAX I do not get the desired output.What should I do?

    • @Drogon-Gaming
      @Drogon-Gaming Před 3 lety

      just give 999 or any big integer ! or u can include header file

    • @kriptoedits9978
      @kriptoedits9978 Před 2 lety

      Hey btw why we initialise int min = INT_MAX means why we don't do Int min = INT_MIN why it is opposite

    • @tejasjoshi1907
      @tejasjoshi1907 Před 2 lety +3

      @@kriptoedits9978 because as we want our answer to be minimim so for comparison we want something which is bigger than that particular number at which we are currently sitting though we can also take a bigger number like 999 but its good practise to use INT_MAX for it ..and it is opposite if in case we want our answer to be minimum then at that point we initialize it as INT_MIN (or we can also take it as 0)

    • @-ADeepikaUsike
      @-ADeepikaUsike Před 2 lety

      Use #include

  • @Rohan-hj9gg
    @Rohan-hj9gg Před 3 lety

    Bhai strings pe ana toh 3-5 questions karna per day. Please bhai

  • @mahipalsingh-yo4jt
    @mahipalsingh-yo4jt Před 3 lety

    is there any solution other than sorting...?

  • @ericMotivation
    @ericMotivation Před 3 lety +2

    give me some tips to increase thinking power of such type of questions.

  • @ratneshjain2321
    @ratneshjain2321 Před 3 lety +4

    Tumko ksm h bell icon ki ydi ye series bich m bnd ki to ❤️ mohhbt h

  • @vaibhavkumar903
    @vaibhavkumar903 Před 2 lety +3

    are bhai code hi padna tha to tumhari video kyu dhekhae

  • @rishiSingh0898
    @rishiSingh0898 Před 2 lety

    I am not able to understand from ur video

  • @swarupcodes
    @swarupcodes Před rokem

    Explanation is not very clear. Just iterating through the solutions.

  • @manassahoo2750
    @manassahoo2750 Před rokem

    Sir first explain the question then provide solutions.

  • @manideepkumar959
    @manideepkumar959 Před 2 lety

    Are bhayya why don't u speak in English

  • @yashsolanki2357
    @yashsolanki2357 Před rokem +1

    bhai tune sirf code karke dikhaya logic to bataya hi nai gfg solution me se dekh ke to koi bhi upload kar sakta hain. question ko thik se samjana sikho youtube me add se paise kamane ke liye kuch bhi mat karo

  • @parthbadkul3524
    @parthbadkul3524 Před 2 lety

    Tbh this problem is poorly constructed

  • @HappyShorts598
    @HappyShorts598 Před 5 měsíci

    No explanation.😂😂only write the code.dont waste our time bro

  • @abhijeetbasfore6816
    @abhijeetbasfore6816 Před 2 lety

    long long findMinDiff(vector arr, long long n, long long m){
    //code
    sort(arr.begin(),arr.end());
    long long i=0,j=0,mx=INT_MIN,mn=INT_MAX,res=INT_MAX;
    while(j