BS-14. Find the Smallest Divisor Given a Threshold | Binary Search

Sdílet
Vložit
  • čas přidán 26. 07. 2024
  • Problem Link: bit.ly/3Cl6KB6
    Notes/C++/Java/Python codes: takeuforward.org/arrays/find-...
    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/takeUforward
    0:00 Introduction of Course

Komentáře • 142

  • @promamondal6863
    @promamondal6863 Před rokem +58

    This problem is literally the same as koko eating bananas problem, yet you took the time to explain it separately. Kudos for the hardwork

  • @sujalgupta6100
    @sujalgupta6100 Před 2 měsíci +7

    solved by myself, thanks a ton!!!!!!!!!!!!!!!!!!!!!!!!

  • @Satyendra_Prakash17
    @Satyendra_Prakash17 Před 28 dny +9

    solved in just one go without a single error with intuition from previous videos. Love you striver for such amazing content..

  • @ajayramola9386
    @ajayramola9386 Před rokem +34

    just watched the prev question vid and solved this question by myself only thanks striver absolutely the best DSA course

  • @AdityaKumar-be7hx
    @AdityaKumar-be7hx Před 11 měsíci +39

    Here's an easy way to find the ceil while doing division: return (x+y-1)/y;
    If we want to avoid overflow with x+y then simply doing 1+(x-1)/y will work too

    • @syedfazil2998
      @syedfazil2998 Před 8 měsíci +1

      Can you explain this please?

    • @bishalpaul18
      @bishalpaul18 Před 4 měsíci

      Literally found the same thing in codeforces blog article

    • @crazybro4383
      @crazybro4383 Před 3 měsíci

      int maxx(vector nums){
      int n = nums.size();
      int ans = 0;
      for(int i=0; i

  • @udaykulkarni5639
    @udaykulkarni5639 Před 4 měsíci +3

    1 min 50 seconds into the video and I know how to solve this question. lol. What a guy!! people like you are true 💎. hats off.

  • @pizzagamingyt9712
    @pizzagamingyt9712 Před rokem +15

    Striver Explanation is so smooth and easy to understand ..❣

  • @Josuke217
    @Josuke217 Před 2 dny

    Your explanation is really good, I actually regret wasting 3.5 months: March , April, May and June. Babbar has explained binary search in a very poor manner. I couldn't solve most questions. My friends told me to learn it from this channel but looking at the playlist length , I avoided it . Totally my fault, and here I am able to atleast think and come up with a solution. Now I understand why people say learn from Striver.

  • @adityarajvermaa
    @adityarajvermaa Před 11 měsíci +8

    i coded it by myself...understanding the previous videos .......thank you bhai.........my thinking capacity is increasing

  • @saswatrath4646
    @saswatrath4646 Před 3 měsíci +1

    I saw comments before watching the video, people were able to solve so I got jealous and solved it on my own 😂 thank u striver

  • @adveshdarvekar7733
    @adveshdarvekar7733 Před 10 dny

    I solved this problem without seeing the video. Thank you for teaching me so well!

  • @sakshinaruka3440
    @sakshinaruka3440 Před rokem +12

    Understood :), Thank so much , i always faced difficulty in when i should take high=mid-1 or high=mid . You teach all the ques with the same pattern. This helped me a lot

    • @akuma_168
      @akuma_168 Před 10 měsíci

      hey I want to know how to figure out when to decide high= mid-1 or mid. In which video he explained this concept.

    • @anishsingh9043
      @anishsingh9043 Před 10 měsíci

      @@akuma_168
      You always do mid-1 because you are dividing your given data into two data set leaving the middle element. Cause you have already checked for the middle element. And after checking the middle element, you make a decision that you have to go left or you have to go right.
      I hope this made you clear. I may be wrong and correct me if I am. I am a newbie too.

  • @Harsh-og5xr
    @Harsh-og5xr Před 9 měsíci +2

    too good bro... after smashing dp playlist im here and with each video my confidence level on BS Q increasing rapidly🔥🔥

  • @user-rf7ri9pw9p
    @user-rf7ri9pw9p Před 10 měsíci

    Absolute amazing DSA course thank you able to solve this myself

  • @cinime
    @cinime Před rokem

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

  • @gajsinghrathore8800
    @gajsinghrathore8800 Před rokem +2

    i literraly solved by myself it is same as koko eating bananas ,tank you striver bhaiya for this amazing content,i am paying my internet bills to watch this types of content only

  • @RajNamdev_19
    @RajNamdev_19 Před 20 dny +1

    Thanks Bro, Now I am getting Binary Search and able to do by myself ;) Understood;

  • @anshror2583
    @anshror2583 Před 3 měsíci +2

    This is literally same as Koko eating banana well explained brother

  • @udatyadeb101
    @udatyadeb101 Před 6 měsíci

    wow! did this one on my own as well! Thanks to you!

  • @SumitSingh-dc8pm
    @SumitSingh-dc8pm Před 7 měsíci

    Completed this today, thanks again

  • @user-ti3bd8mp1w
    @user-ti3bd8mp1w Před rokem

    understood
    Thank you striver for such an amazing explanation

  • @hareshnayak7302
    @hareshnayak7302 Před 3 měsíci

    Understood,Thanks Stirver for this amazing video.

  • @eklavya22k34
    @eklavya22k34 Před 6 měsíci

    Thanks a ton for all the help. Great work. Noble deeds.

  • @googleit2490
    @googleit2490 Před rokem

    Understood :)
    Coded whole code on my own,thanks!!

  • @joeljacob4685
    @joeljacob4685 Před 9 měsíci +1

    Thanks for the explanation !! I was able to solve the question on my own🙂

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

    Thank you Striver understood everything

  • @harshitjaiswal9439
    @harshitjaiswal9439 Před rokem

    Understood Striver! You are amazing!

  • @AnmolGupta-oj4lm
    @AnmolGupta-oj4lm Před 11 měsíci

    Understood Very Well!

  • @user-or5oz1pk2x
    @user-or5oz1pk2x Před 2 měsíci

    Thanks a lot Striver Bhaiya

  • @ABCDEFGH-fz5ju
    @ABCDEFGH-fz5ju Před 2 měsíci

    understood thoroughly

  • @YourCodeVerse
    @YourCodeVerse Před 7 měsíci

    Understood✅🔥🔥

  • @gunjjoshi5687
    @gunjjoshi5687 Před 9 měsíci

    Thank you.

  • @shamikbhattacharjee7321
    @shamikbhattacharjee7321 Před rokem +4

    Very much similar to the question of Koko eating bananas.(Just my opinion)

  • @user-is6ky7pp2n
    @user-is6ky7pp2n Před měsícem

    Understood !! 😎😎

  • @culeforever5408
    @culeforever5408 Před 8 měsíci +1

    understood 😇

  • @per.seus._
    @per.seus._ Před 11 měsíci +1

    understood💝

  • @user-js1rx8rs9p
    @user-js1rx8rs9p Před 3 měsíci

    its just like a previous one , i did it bro

  • @senseiAree
    @senseiAree Před 9 měsíci

    Understood ❤

  • @anshpradhan1954
    @anshpradhan1954 Před 2 měsíci

    understood brother

  • @humanity7880
    @humanity7880 Před rokem

    understood!

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

    understood. solved by myself

  • @KartikeyTT
    @KartikeyTT Před měsícem +1

    ty sir

  • @Gaurav_Tripathi_
    @Gaurav_Tripathi_ Před 8 měsíci

    Understood..!!

  • @nayankhuman1043
    @nayankhuman1043 Před 8 dny

    Understood :)

  • @ishangujarathi10
    @ishangujarathi10 Před rokem +2

    coded it all by myslef!!! thank you soo much for such an amazing playlist!!! following each and every video of yours!!

    • @pryansh8333
      @pryansh8333 Před rokem +1

      no big deal !!
      its similar to koko eating bananas.. me n my friends all were able to solve it... Ha Ha Ha !!

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

      yeah its the same as koko eating bananas just the language is different😁

  • @LinhHoang-ml1qo
    @LinhHoang-ml1qo Před 9 dny

    Thank you Striver, you are the best of DSA CZcamsr

  • @pratikshadhole6694
    @pratikshadhole6694 Před rokem

    understood😍

  • @user-js1rx8rs9p
    @user-js1rx8rs9p Před 3 měsíci

    tq striver

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

    Understood

  • @aditya8sharma
    @aditya8sharma Před rokem +2

    Please update the CP sheet, to a checklist kind of a sheet, just like you have done with the DSA sheets!

  • @user-oz7ol1bg3n
    @user-oz7ol1bg3n Před rokem +1

    understood

  • @pihus3498
    @pihus3498 Před rokem

    understood :)

  • @Dipanshutripathi2407
    @Dipanshutripathi2407 Před 9 měsíci

    Another Hard Problem is made easy here.

  • @UdayGarg
    @UdayGarg Před měsícem +1

    solved it by myself

  • @soni.himansh
    @soni.himansh Před rokem +3

    same as Koko Eating Bananas

  • @lazyemperor5182
    @lazyemperor5182 Před rokem +1

    Sliding window par small series bhi karwado

  • @girikgarg8
    @girikgarg8 Před 10 měsíci

    Done

  • @arunmahajan1028
    @arunmahajan1028 Před 8 měsíci

    we can also start low from array min

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

    If there are 0s in the array then the
    Return -1 if n>limit condition will fail

  • @aatirali7696
    @aatirali7696 Před rokem

    Understood:)
    Thank you striver for such a great content ❣❣

  • @saketjaiswal9381
    @saketjaiswal9381 Před rokem

    done

  • @crazybro4383
    @crazybro4383 Před 3 měsíci

    int maxx(vector nums){
    int n = nums.size();
    int ans = 0;
    for(int i=0; i

  • @VishalGupta-xw2rp
    @VishalGupta-xw2rp Před 9 měsíci

    12:10 Reverse Polarity

  • @VivekKumar-kx2zf
    @VivekKumar-kx2zf Před 2 měsíci +2

    hello striver maybe we can do the binary search from min(arr) to max(arr) that will have less range of binary search and it is also working correctly

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

    The loop that finds the maximum value in the array (maxi) has a time complexity of O(n), where n is the length of the array.
    The binary search is performed on the range from 1 to maxi. The binary search algorithm has a time complexity of O(log(maxi)), where maxi is the range of possible divisors.
    Inside the binary search loop, the sumByD function is called, which has a time complexity of O(n). This is because it iterates through the entire array.
    Therefore, the overall time complexity is O(n) (for finding maxi) + O(log(maxi)) (for binary search) + O(n) (for sumByD) = O(n + log(maxi) + n).
    Sir, so what's the time complexity of this code?
    Thank You!!

  • @user-zm6ih2vl2g
    @user-zm6ih2vl2g Před rokem +1

    First view ❤

  • @funandfrustration6492

    Bro,how much time is needed to practice DSA?

  • @raghavkansal3765
    @raghavkansal3765 Před rokem +1

    "understood"

  • @garimaarora5311
    @garimaarora5311 Před rokem +3

    can we take low=min_element in array rather than we take low=1??

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

      no bcoz...we choose lo and high based upon the values where the dummy_threshold can reach max and min...so if u find the dummy_threshold value by using 1 it will be the maximum u can get but if u find the dummy_threshold using lo then its greater then that of 1 . Along with that hamare question my ek possiblity ye bhi ho sakti hai ki threshold value kaagfi jada di ho toh us case me tum agar max threshold nikali hai toh 1 se hi nikalegi .

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

    Habibi ye toh lappu sa question hai .....khud hi ban jave .....shukriya

  • @infinity2creation551
    @infinity2creation551 Před 9 měsíci

    Last 2 videos.. Really related to this question.....
    Advice = plz watche last 2 videos

  • @ganeshmula4508
    @ganeshmula4508 Před 10 měsíci

    🙌🙌🙌🙌

  • @mansisethi8127
    @mansisethi8127 Před 7 měsíci +1

    I didn't understand why he took the ceil ?

  • @modiji8706
    @modiji8706 Před 9 měsíci

    able to solve myself after 3:52

  • @jagadeeshp1163
    @jagadeeshp1163 Před 9 měsíci

    US💯

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

    what is int div?

  • @harshith1424
    @harshith1424 Před rokem

    Consistency ❤❤

  • @user-qf6it2em2h
    @user-qf6it2em2h Před rokem +1

    Bhaiyaa I have just passed class 12 and my result of jee is not good enough to get any nits,gftis........so, please answer to my query that what would be better choice for me either joining newton school of technology or scaler school of technology Brand new bs ms programme OR, should taking a drop for cse at NIts,IIITS,Gftis........????....
    please give your suggestion🙏🙏🙏🙏🙏 please answer my queries ASAP

    • @22gauravkumar70
      @22gauravkumar70 Před rokem

      both the above school you mentioned are bullsh@t , pls don't" join either . Go for Thapar or take drop and join IIT,NITS,IIITs .

  • @rohinisharma4043
    @rohinisharma4043 Před rokem +1

    Hello bhaiya ! i have been following your dsa since a long time ...now-a-days there are a lot of courses that are floating on yt (paid approx 5k or 6k ) each and every youtubers i now from faraz , nishant , anuj apna college everyone is selling their courses that are starting fron july ownwards ...but i know no can beat your level of dsa problem solving ....are u gonna launch any dsa course too ?? ...i trust only u when it comes to dsa ...and dont want to waste money on this courses unless it is yours ... please reply bhaiya are u launching any dsa course ....??

    • @takeUforward
      @takeUforward  Před rokem +2

      no

    • @Abcxyz.24
      @Abcxyz.24 Před rokem +5

      dont even think of buying their courses. follow him and you are good to go. just gotta have sume discipline and consistency

    • @vishaljoshi7752
      @vishaljoshi7752 Před rokem +1

      youtube pe sub hai or kya chahiye 300 400 problem deklo na hr topic me se

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

    my n>limit but where is n declared timing 15:28 sec

  • @vishaljoshi7752
    @vishaljoshi7752 Před rokem

    same as koko

  • @maitohpughu5714
    @maitohpughu5714 Před rokem

    *************JAVASCRIPT CODE*************
    function smallestDivisor(arr, threshold) {
    let left = 1,
    right = (ans = Math.max(...arr));
    while (left Math.ceil(el / mid))
    .reduce((acc, curr) => curr + acc, 0);
    if (sum

  • @MJBZG
    @MJBZG Před 25 dny +1

    math version of koko problem

  • @parthanuj8611
    @parthanuj8611 Před 6 měsíci

    bhai kab khatm hogi ye series

  • @crimemastergogo710
    @crimemastergogo710 Před 6 měsíci

    ###Use float datatype to use ceil function###3
    bool poss(int mid,vectorarr,int limit){
    for(int i=0;i

  • @ambaradhikari7425
    @ambaradhikari7425 Před rokem +1

    bro if possible try to solve 2-3 problems in one video like you did for array

    • @takeUforward
      @takeUforward  Před rokem +1

      Reduces the search index

    • @ambaradhikari7425
      @ambaradhikari7425 Před rokem +1

      @@takeUforward okay, I was asking so that you can complete all the remaining ones as early as possible, string linkedlist ,bit manipulations, stack ,queue so many things left and placement season coming so we can cover all the lectures, Ik you have other works but the way you explain concepts I want to study everything from you , if possible please try to cover up all as early as possible .

    • @pratikshadhole6694
      @pratikshadhole6694 Před rokem +1

      @@ambaradhikari7425 same but individual videos are better for people having less attention span(like me)😅

    • @ambaradhikari7425
      @ambaradhikari7425 Před rokem

      @@pratikshadhole6694 yeah same but videos 3-4 ho ya phir 1-2 , agar problems solve ho raha hai toh koi dhikkat nehi? Btw have you just started doing dsa?

  • @pranshu7592
    @pranshu7592 Před rokem +1

    Bro plz complete this series before july 1

  • @snehashisratna9074
    @snehashisratna9074 Před 8 měsíci

    bhai ...ap odia ho kya ? i mean ... are you from odisha ?

  • @harshdhawale2669
    @harshdhawale2669 Před rokem

    First comment

  • @cenacr007
    @cenacr007 Před 9 měsíci

    us

  • @jagadeeshp1163
    @jagadeeshp1163 Před 9 měsíci

    if you watch koko bananas question this question is a real banana

  • @dewanandkumar8589
    @dewanandkumar8589 Před 6 měsíci

    Understood

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

    understood

  • @shubhramoysarkar4319
    @shubhramoysarkar4319 Před rokem

    understood:)

  • @dhyeyparekh4994
    @dhyeyparekh4994 Před 3 měsíci

    Understood

  • @nihalsingh6233
    @nihalsingh6233 Před 8 měsíci

    Understood

  • @anand_yv
    @anand_yv Před 10 měsíci

    Understood

  • @ankithac5520
    @ankithac5520 Před rokem

    Understood

  • @abhishekprasad010
    @abhishekprasad010 Před 3 měsíci

    Understood

  • @himanshidafouty347
    @himanshidafouty347 Před 2 měsíci

    Understood