BS-15. Capacity to Ship Packages within D Days

Поделиться
HTML-код
  • Опубликовано: 5 окт 2024
  • Problem Link: bit.ly/43QDpdG
    Notes/C++/Java/Python codes:
    We have solved the problem, and we have gone from brute force and ended with the most optimal solution. Every approach's code has been written in the video itself. Also, we have covered the algorithm with intuition.
    Full Course: bit.ly/tufA2ZYt
    You can follow me across social media, all my handles are below:
    Linkedin/Instagram/Telegram: linktr.ee/take...
    0:00 Introduction of Course

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

  • @ArpanChakraborty-do6yz
    @ArpanChakraborty-do6yz 8 месяцев назад +57

    bhaiya i have done the last two problems on my own without watching your solution and now i am gaining a little bit of confidence that i can also do.... it is not that i haven't done any problem on my own but it was after completing your playlist of that topic and then doing other problem of that topic, but it is the first time i am doing this before completing this playlist of binary search,,, thank you bhaiya , you teaching style is just awesome😍😇😇

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

      gawd

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

      dude exactly same, i was also able to solve this one and the last one on my own. this happened for the first time!!

    • @luckygarg2294
      @luckygarg2294 3 месяца назад +1

      @@arujgarg7267 Exactly same... Solved this and previous 2 problems on my own

  • @Satyendra_Prakash17
    @Satyendra_Prakash17 3 месяца назад +21

    solved it on my own , woohoo confidence is just sky rocketing !! thank you striver

  • @lucario404
    @lucario404 Год назад +13

    aapki videos shuru majboori mei kiye the,
    lekin ab maza aane laga hai :)

  • @sauravchandra10
    @sauravchandra10 Год назад +19

    The way you explain and write the code so clearly is what is so unique about you. Clearly understood, thanks!

  • @grannymuffins8882
    @grannymuffins8882 Год назад +12

    bro this is one of the best cheat sheet.
    the way you split each patterns into sub patterns is great
    Would be great if you continue to find sub patterns within existing patterns

  • @samreenimam8608
    @samreenimam8608 9 месяцев назад +4

    SALUTE HAI BHAI..!! kya smjhaya hai ..itna easy logic!!... blown away! Thank you rahega

  • @siddharth892
    @siddharth892 8 месяцев назад +10

    One more thing that should be added into the question is that the weights need to shipped in order. I think if we are to club the minimum and the maximum weights together then 11 would be the answer for this [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Days = 5

    • @divingdabbler2035
      @divingdabbler2035 6 месяцев назад +1

      Ikr, right now the question seems more like binary search over series of knapsacks instead of contiguous sums

    • @harshvardhansankpal716
      @harshvardhansankpal716 5 месяцев назад

      yup, i was literally thinking the same thing, i thought if i only take consecutive days i might get error in leetcode.

  • @abhaypandey2668
    @abhaypandey2668 8 месяцев назад +2

    I watched 5 videos and was trying to understand this for last 3 days, but the way you explained it has become like cutting butter for me now..thanks a lot

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

      Can u share where were doing this problem, was it a platform other than leetcode ? Kindly share

  • @rushithagudipudi7742
    @rushithagudipudi7742 5 месяцев назад +3

    ❤understood, next level lecture , this is what the tier 3 students wish to listen in classroom

  • @adityarajvermaa
    @adityarajvermaa Год назад +4

    man..even this one i coded down myself...understanding the previous ones...thanks bhai

  • @vishious14
    @vishious14 8 месяцев назад +1

    Was able to solve this on my own. This question is similar to minimum days to make m bouquets. Thanks a tonne, Striver !!!!

  • @karthik-varma-1579
    @karthik-varma-1579 Месяц назад +1

    For Least Never Return at first if you get desired answer store it in answer variable and check it till end if there still exists lesser value
    Thank You Striver.

  • @ravindardeeti4364
    @ravindardeeti4364 Месяц назад +1

    your are totally amazing striver bhai , i got the solution after your explanation 💓💓

  • @prabhatece0488
    @prabhatece0488 9 месяцев назад +12

    At 15:11 bhaiya you said high=23, but actually mid was=32 before, so new high=mid-1=32-1=31

    • @kanhiyasharma3648
      @kanhiyasharma3648 4 месяца назад

      hnn bhaii mee bhi yhi soch rhaa thaa tbbhi comment dhundh rha tha ki kisi nee to kia hogaa

  • @teeyaojha4365
    @teeyaojha4365 Год назад +10

    mistake at 15:03 it will come to 31 not 23, but its ok. under stood.

  • @sayandey2492
    @sayandey2492 7 месяцев назад +1

    Wow...the portrait of the ship is so good 😃

  • @Codro09
    @Codro09 6 месяцев назад +1

    I was able to code in less than 7 mins (thala for a reason....naah, obv u the reason).....thanks a lot.

  • @DEVILGAMING-to6bn
    @DEVILGAMING-to6bn Год назад +44

    sorry to say but studying DSA with you and LOVE sir combined is just better than best

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

    Crystal clear explanation striver... Clearly understood everything...Thanks a lot for this awesome series.

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

    Thanks man! you make the code look so simple, Idk why I end up writing a long and complex brute force code even though it works..

  • @Isagi__000
    @Isagi__000 6 месяцев назад

    wow man, i could able to solve this on my own. i am watching this because i just wanna see your explination, i am following your playlist, learning in a structure and doing similar problem really helps in undertanding the concept, thank man. also after solving koko banana problem, solving prev problem in this playlist find the smallest divisor, really cake walk.
    tha't it, tho i don't comment that much, you are helping many ppl like me. thanks for doing all the work.

  • @tanishkumar5827
    @tanishkumar5827 9 месяцев назад

    thank u striver bhaiyaa!you made divide and conquer a cakewalk! this ecstatic feeling is so morale boosting as i did this problem by myself in a single go under your guidance ! much love

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

    superb explanation, 80% coded it myself, tysmm

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

    slight improvement, the max can also be sum(weights)-days+1. This is because in worst case you can ship the item with max weight on day 1, then remaining items combination on each days

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

    Amazing explanation as always Understood

  • @valiz2628
    @valiz2628 Месяц назад +4

    S + T + R + I + V + E + R = 7 , Thala for a reason

  • @K_EN_VisheshSaini
    @K_EN_VisheshSaini 11 месяцев назад +2

    Another code for same approach:-
    bool f(int mid, vector &weights, int d){
    int day = 1, temp = mid;
    for(int i=0;i

    • @Max-E-Mum
      @Max-E-Mum 19 дней назад

      Woah ive got a similar approach as well
      class Solution {
      public:
      bool check(vector& v, int mid, int days) {
      int tmp = mid;
      for (auto e : v) {
      if (tmp >= e) {
      tmp -= e;
      } else {
      days--;
      if (days == 0) {
      return false;
      }
      tmp = mid;
      tmp -= e;
      }
      }
      return true;
      }
      int shipWithinDays(vector& v, int d) {

      int low = *max_element(v.begin(), v.end());
      int high = accumulate(v.begin(), v.end(), 0);
      int ans;
      while (low

  • @saurabh_agrawal7
    @saurabh_agrawal7 24 дня назад

    bhaiya i was able to solve the problem on my own without watching your solution, tysm bhaiya 🙂

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

    - [00:17](ruclips.net/video/Mde2q7GFCrw/видео.html) The problem is about finding the minimum capacity needed to ship packages within a given number of days.
    - [01:49](ruclips.net/video/Mde2q7GFCrw/видео.htmlm49s) An example is given where if the ship's capacity is 100, all packages can be shipped in one day.
    - [03:22](ruclips.net/video/Mde2q7GFCrw/видео.htmlm22s) It is demonstrated that a capacity of 10 leads to shipping taking more than the given number of days.
    - [04:20](ruclips.net/video/Mde2q7GFCrw/видео.htmlm20s) Increasing the capacity to 15 allows shipping all packages within the given days.
    - [06:11](ruclips.net/video/Mde2q7GFCrw/видео.htmlm11s) The answer must be between the maximum weight of a product and the sum of all weights.
    - [08:01](ruclips.net/video/Mde2q7GFCrw/видео.htmlm1s) A function is described to find the number of days required to ship with a given capacity.
    - [12:32](ruclips.net/video/Mde2q7GFCrw/видео.html2m32s) The initial solution has a time complexity of O(N^2) due to linear search.
    - [13:54](ruclips.net/video/Mde2q7GFCrw/видео.html3m54s) Binary search is introduced as an optimization technique to find the minimum capacity needed.
    - [16:49](ruclips.net/video/Mde2q7GFCrw/видео.html6m49s) The binary search approach eliminates capacities that are not possible and updates the answer with the lowest possible capacity.
    - [18:25](ruclips.net/video/Mde2q7GFCrw/видео.html8m25s) The time complexity of the binary search solution is O(N * log(Sum - Max)), where N is the number of items and Sum and Max are the sum of weights and the maximum weight, respectively.
    - [19:50](ruclips.net/video/Mde2q7GFCrw/видео.html9m50s) The C++ code for the binary search solution is demonstrated, and viewers are encouraged to find code for other programming languages in the video description.

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

    Understood! Super excellent explanation as always, thank you very much for your effort!!

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

    2 things to keep in mind
    The range is - low (max of all the weights), high (summ of all the weigths)
    The logic for helper function will do day++ if the load value is not.
    UnderStood

  • @SumitSingh-dc8pm
    @SumitSingh-dc8pm 9 месяцев назад

    *Completed now, thanks for such lovely content.*

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

    Thank You Striver understood everything🙂

  • @AtulKumar-c4x7l
    @AtulKumar-c4x7l Год назад

    Understood
    Thank You striver for such an amazing explanation

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

    solved it on my own, yay!

  • @TON-108
    @TON-108 11 месяцев назад +1

    Understood! Thanks :)

  • @AnmolGupta-oj4lm
    @AnmolGupta-oj4lm Год назад +1

    Understood Very Well!

  • @CrazyHunk14
    @CrazyHunk14 7 месяцев назад +1

    well well well now i am solving leetcode medium question without any help in the optimal way thank you striver!

  • @gouravbhatt479
    @gouravbhatt479 3 месяца назад +1

    i was able to do it by myself...........thanks to striver;
    return happy😆;

  • @sujalgupta6100
    @sujalgupta6100 4 месяца назад

    solved by myself, All thanks to you.

  • @ateequrrahaman8902
    @ateequrrahaman8902 20 дней назад

    understood the complete concept

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

    understood striver ,thank you so much

  • @SWAPNILSHIKHA-l8j
    @SWAPNILSHIKHA-l8j 5 месяцев назад +1

    It was just an awesome video... but pls tell me... why int days is initialised with 1 .... why not int days=0;

  • @kallabhargavi-d7j
    @kallabhargavi-d7j 5 месяцев назад

    you are artist too bro, multitalented striver

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

    mast habibi

  • @saswatrath4646
    @saswatrath4646 5 месяцев назад

    Understood and solved by myself

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

    bhaiya timestamp 15:06
    here mid-1=high=point 31 ,not point 23.

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

    Man, you're legend🤓. Thanks

  • @U2011-n7w
    @U2011-n7w Год назад +1

    nice explanation

  • @BabluKumaraa
    @BabluKumaraa 3 месяца назад +1

    Understood

  • @rajatshukla2605
    @rajatshukla2605 20 часов назад

    Understood!

  • @cyanideyt9579
    @cyanideyt9579 8 месяцев назад +2

    what's the overall time complexity of binary search algorithm in this question
    Because first loop to find summation and maximum element takes O(n) and then the binary search algo which takes (log2(sum-maxi)), after the algo we call the findDays function which take O(n) time complexity.
    so, what's the time complexity of the code
    Thanks You!!

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

      It would be O(n*log(sum-max)), but if you want the exact time complexity taking into account the summation and maximum, then O(2n + n*log(sum-max)).

  • @92AkshaySharma
    @92AkshaySharma 10 месяцев назад

    concise and helpful explaination

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

    Possible function takes time to understand but clear now
    bool isPossible(vector &weights, int d, int mid){
    int dayCount = 1;
    int sum = 0;
    for(int i = 0; i < weights.size(); i++){
    sum += weights[i];
    if(sum d){
    return false;
    }
    sum = weights[i];
    }
    }
    return true;
    }

  • @DeepakPatel-d5v
    @DeepakPatel-d5v 5 месяцев назад

    Thanks a lot Bhaiya. You make it easy peasy problem 😀

  • @NazeerBashaShaik
    @NazeerBashaShaik 5 месяцев назад

    Understood, thank you.

  • @ganeshjaggineni4097
    @ganeshjaggineni4097 4 месяца назад

    NICE SUPER EXCELLENT MOTIVATED

  • @rushidesai2836
    @rushidesai2836 4 месяца назад

    Amazing question

  • @shreshtasingh2384
    @shreshtasingh2384 6 месяцев назад

    🔥🔥🔥🔥🔥🔥🔥🔥

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

    Bro by when your whole dsa sheet will be covered, placement coming up?any eta approx?

  • @Omneeshkushwah9695
    @Omneeshkushwah9695 Год назад +6

    @striver please make full dsa paid or free course for competitive programming. I am watching your videos from past 5 months but still I am unable to solve new problems or codeforces ,codechef problems
    Can u make paid live full course .
    I am highly requested to u please launch your course from basic to advanced competitive course. programming course

    • @takeUforward
      @takeUforward  Год назад +7

      join tle-eliminators

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

      @@takeUforward please launch paid cp course we want to learn from you, you explain very well

  • @md.imrankhan6912
    @md.imrankhan6912 Год назад

    Living Legend!

  • @SYCOA12CHAITANYAASOLE
    @SYCOA12CHAITANYAASOLE 4 месяца назад

    Understood !! 😍😍

  • @dhruv2014
    @dhruv2014 9 месяцев назад

    Nice explanation

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

    I have doubt in first example the answer must be 11 as you can take 1st and last element sum everytime so it will be 11

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

      You need to take consecutive elements :)

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

    Can anyone look up at my code and find mistake . I got wrong answer of this ques i.e capacity to ship packages within d days .
    class Solution {
    public:
    int caldays(vector& weights, int cap){
    int sum=0, cnt=0;
    for(auto it: weights){
    sum+=it;
    if(sum

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

      Low has to start from the maxElement in the array, other then that I see no error...

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

      min days will be 1 not 0, just change days = 0 to days = 1 in the caldays function, also start low from the max element in the weights array

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

      @@swapnil243 Correct

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

      @@swapnil243 but it will. Without changing days in cladays

  • @aliakbaransaria3-925
    @aliakbaransaria3-925 Год назад

    Nice explanation 👌

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

    if weights are 1 2 8 9 and d=2 will it give correct answer??

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

    thank you bhaiya

  • @her_soulmate
    @her_soulmate 9 месяцев назад

    Understood 🎉

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

    going smoothly

  • @draxxgamingf.f6369
    @draxxgamingf.f6369 2 месяца назад

    🎉🎉🎉

  • @amittiwari360
    @amittiwari360 5 месяцев назад

    Why the weights are not sorted then also it works, please let me know the function which is inside while loop

  • @YourCodeVerse
    @YourCodeVerse 9 месяцев назад

    Understood✅🔥🔥

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

    Well done

  • @RahulKumar-nd2sp
    @RahulKumar-nd2sp Год назад +2

    15:14 high should be 31 na?

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

    Atlast got it❤❤❤

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

    understood

  • @senseiAree
    @senseiAree 11 месяцев назад

    Understood ❤

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

    Understood !!!!!

  • @Learnprogramming-q7f
    @Learnprogramming-q7f 7 месяцев назад

    Thank you Bhaiya

  • @harshgupta7337
    @harshgupta7337 14 дней назад

    Thanks❤

  • @VinayQ-
    @VinayQ- Год назад

    I think in linear search return the capacity not daysRquired

  • @VishalGupta-xw2rp
    @VishalGupta-xw2rp Год назад

    17:00 opposite polarity

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

    Thank You

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

    Superb sir ❤

  • @RaunitJaiswal-s9v
    @RaunitJaiswal-s9v 18 дней назад

    Done for today

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

    hi @striver , when to use while(high - low >1) condition

    • @takeUforward
      @takeUforward  Год назад +5

      I don't use it anywhere, all problems can be solved without that, if your base is clear

  • @harshitsharma-w8r
    @harshitsharma-w8r 2 месяца назад +1

    all the question are similar to previous one

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

    understooood :)

  • @rohit.mnnita
    @rohit.mnnita Год назад

    17:59

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

    understood!

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

    Day 2 till here

  • @ritikverma3206
    @ritikverma3206 Год назад +5

    First comment

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

    Isn't this same as painter partition problem?

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

    why we are initializing days with 1

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

    This problem is same as BOOK ALLOCATION PROBLEM

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

    Undertsood

  • @maccode07
    @maccode07 7 дней назад

    Understood Striver

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

    "understood"