BS-20. Minimise Maximum Distance between Gas Stations | 3 Approaches | Heap | Binary Search

Поделиться
HTML-код
  • Опубликовано: 15 июл 2023
  • Problem Link: bit.ly/43SkwqA
    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/takeUforward
    0:00 Introduction of Course

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

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

    My bad, a small correction in the code:
    if((arr[i] - arr[i-1]) == (dist * numberInBetween)) {
    numberInBetween--;
    }
    1 == (2 * 0.5)

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

      bhai gfg ki link striver A2Z me add karo plz striver sheet is incomplete without gfg

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

      I am confused.. how it is passing all the test cases then? By the way, Great Explanation love it😇

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

      @@parthibchowdhury5558 I was having the same doubt.. I think it is because the datatype used is "int" and the test cases are weak so there is no test case present where actually the value(arr[i]-arr[i-1]) is perfectly divisible by dist ...because even if you remove this if condition and dont do the decrement, then also the code is working completely fine.

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

      Some test cases are failing because of this condition on gfg, after removing it all cases passed. I'm still confused why this is happening.

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

      if(fmod((long double)(arr[i+1]-arr[i]),mid)==0) numberInBetween--;
      modulus work only in case of int so fmod

  • @visheshupadhyay1774
    @visheshupadhyay1774 6 месяцев назад +70

    Striver is trying his very best to explain but the problem itself is very complex. Hats off bro...

  • @sleepypanda7172
    @sleepypanda7172 Год назад +68

    What a noble man. May he achieve all the success that he wants

  • @kiranmoura2974
    @kiranmoura2974 11 месяцев назад +32

    Sir please continue the series ...a lot of students are waiting eagerly for your videos .

  • @zaidwani1473
    @zaidwani1473 5 месяцев назад +7

    This guy is a pure genius. The efforts he put in to explain such a complex problem with such simplification requires a genius mind. Kudos to your efforts.

  • @habeeblaimusa4466
    @habeeblaimusa4466 Год назад +57

    Guys those of you saying use low

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

      I think all almost all of them😅

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

      @@infinityzero2321 yes bro

    • @GeneralistDev
      @GeneralistDev 11 месяцев назад +7

      please explain here only, I don't have time to go through whole playlist

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

      @@GeneralistDev nhi bateynege poora dekh

    • @arunm619
      @arunm619 21 день назад +1

      @@GeneralistDev its just a pattern we follow to solve the problems to get the polarity principle where the answer we are looking for always resides at low index for
      y.y.y.y.n.n.n.n.n problems.

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

    Though Striver Bhaiya is at a very nice position today, but according to me, he deserves even more...................God Bless You Bhaiya.........🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
    Thanks a ton..........🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻

  • @i_m_phoenix87
    @i_m_phoenix87 11 месяцев назад +4

    it's so hard to wait for gem videos like this , I got a very clear view of BS just because of you bhaiya. Thanks

  • @rohitsai806
    @rohitsai806 10 месяцев назад +11

    Hard problem to absorb...! Kudos to your efforts, hats off Striver for your dedication

  • @Shunya_Advait
    @Shunya_Advait 10 месяцев назад +11

    Understood Sir, It is most amazing problem I find in binary search and really required more attention, and Sir you have explained it very well in three different approaches , thanks a lot for the video.

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

    Dedication, Made Respect to him!! GIving a complete insight on the topic is just insane and very few people do it!

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

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

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

    The best DSA course on the Internet

  • @himanshuranjan8344
    @himanshuranjan8344 Год назад +9

    Effort level:- Inspirational 🏆

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

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

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

    Amazing explanation so far🔥

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

    Amazing! Dedication is super! Thank you Striver!

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

    Can't thank you enough for this amazing content!! Explained so perfectly!! Thank you Striver for this course!!

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

    Thank you so much Striver.Loved it.💖

  • @Gaurav-vl6ym
    @Gaurav-vl6ym 9 месяцев назад

    no one explains better than you ,thank you

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

    Thank you for explaining this difficult question so brilliantly.

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

    Very well understood all three approaches specially priority queue one method

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

    Great Approach. Really loved the explanation. You made such an hard question easy to understand. Thanks❤❤

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

    Bhai last decimal vala sach me hard h... 2 solution to iska easily samjh gaya. I will give again try tom , at least 30 % aaj samjh me aa gaya.

  • @DR-mq1le
    @DR-mq1le 11 месяцев назад +2

    striver bhaiya when can we expect the strings playlist? ur explanation is far better than anyone else . and before the fanboys come at me saying that " striver has a job , have patience" , im just asking when we can expect not forcing him :)

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

    hats off to your efforts sir, very well explained

  • @preetisahani5054
    @preetisahani5054 9 месяцев назад +1

    Awesome explanation. still trying to absorb last approach

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

    UnderStood Striver, and that's awesome. Thanks for making this

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

    just wow.. u really inspire me sir..

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

    Hats off to the explanation. Awesome work sir

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

    Great video sir! Hats off!

  • @yaminireddy3321
    @yaminireddy3321 23 дня назад

    Thank You Striver for the best explaination

  • @-RAJSINGH
    @-RAJSINGH 5 дней назад

    Best explanation! this was my first hard problem, but you made it so easy to understand. Hats off bhaiya!!!!

  • @nookalareshwanth1785
    @nookalareshwanth1785 6 месяцев назад +2

    This surely is an amazing problem

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

    Done! Nicely explained

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

    Hats off to your hardwork brother 🤍🫡

  • @user-ik3qu5uy5e
    @user-ik3qu5uy5e 5 месяцев назад

    sir ek hi dil hai kitne baar jeetoge ❣

  • @sujalgupta6100
    @sujalgupta6100 2 месяца назад +1

    I would rather fail interview than trying this binary search solution
    took me 3 hours to make through this video

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

    Amazing content bro... Love you so much

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

    His efforts>>>>

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

    you're doing great job

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

    Good explanation, please start string then linkedlist, also please add gfg links

  • @Bhalu-kl7sq
    @Bhalu-kl7sq 8 дней назад

    maybe high have to watch again after sometime awesome video

  • @vrushabhjoshi3155
    @vrushabhjoshi3155 21 день назад

    Hats off to your hard work 🫡

  • @AKASHKUMAR-li7li
    @AKASHKUMAR-li7li 4 месяца назад

    You are just awesome man👍

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

    keep up the good work bro...

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

    Striver bhai plzz start string series i am waiting for it.... ❤️❤️❤️

  • @AmanKumar-qz4jz
    @AmanKumar-qz4jz 10 месяцев назад

    THANKU SO MUCH SIR!!! LOVE U MAN

  • @jayant1407
    @jayant1407 Год назад +16

    hey Striver , Just a Small request sir can pls give us the , List of Topics that you will be covering monthly
    So it will easy for us to knew till when we are able to complete the dsa

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

    Why are the videos not coming? please make a video regarding when the future videos will be released. I am very excited.

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

    you are great bhaiya love you❤

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

    best video till date

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

    Words cannot portray how much grateful I am to you and your teaching. Never ever I have understood a topic with such clearness and depth. Thanks to you I could solve all the problems right from Aggressive cows till Painter's Partition without even looking at any hints.Cannot explain the surreal feeling of getting green ticks on a LC Hard problem that too in the first submission itself!!

  • @Dontpushyour_luck
    @Dontpushyour_luck 9 месяцев назад +1

    did this question even before watching video. you taught binary search so good that I was able to do it so easily

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

    NICE VIDEO UNDERSTOOD !!!

  • @atharva..deshmukh
    @atharva..deshmukh 15 дней назад

    Very nice explanation

  • @prabhatmishras421
    @prabhatmishras421 16 дней назад

    Madddd Respect man♥♥

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

    From Bruteforce -> better -> optimal. It was really hard question in BS. But anyways Thank You Striver for best explanation.

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

    last wali ne dimaag hila daala bhai!!

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

    Understood✅🔥🔥

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

    Sir pls continue the series..

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

    please striver post the next videos asap we are eagerly waiting for ur vds please, placement start ho gya please complete the series

  • @kabirkapoor9149
    @kabirkapoor9149 11 месяцев назад +8

    Striver please please please Continue with the series ..... Placements are approaching , Completely dependent on ur way of teaching .....Kindly upload videos and complete dsa as early as possible

    • @DR-mq1le
      @DR-mq1le 11 месяцев назад

      final year aswell?

  • @aps8874
    @aps8874 9 месяцев назад +1

    Super❤‍🔥

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

    Striver you are GOD!!!

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

    Understoood!!!!!

  • @abdussalam-4836
    @abdussalam-4836 7 дней назад

    A small improvement in brute force is u don't need to have a howmany vector u can use the pair in pq

  • @Freefire-hp4zz
    @Freefire-hp4zz Год назад +5

    Bhai Will You Continue To Upload DSA COURSE VIDEOS AFTER BINARY SEARCH??? PLEASE UPLOAD STRING PLAYLIST BHAI

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

    Stack & Queue Series Please Also Linked List.

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

    Bhai please continue the series

  • @anugandulasricharan3735
    @anugandulasricharan3735 Час назад

    Thanks.Understood

  • @user-tk2vg5jt3l
    @user-tk2vg5jt3l 5 месяцев назад

    Thank you Bhaiya

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

    Subscribed Nice👌

  • @sdsingh3577
    @sdsingh3577 Год назад +11

    Plz bhaiya upload more and more videos as soon as possible......plz bhaiya

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

      Th ode question khud se bhi try kiya karo 🥲

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

      @@Daddy30011 not question bro.....I say introduction tutorial of pointer and some other

  • @JayPatel-sn7it
    @JayPatel-sn7it Год назад +5

    Bhai site thik kar rahe ho to sath me CN ki jagah GFG ki link dal do please...
    Or you can make another section beside of CN links, for GFG links please 🥺

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

    bhai can yu tell how many month yu will take complete this course actually i am new this chanel approx 3 month

  • @bharathi66
    @bharathi66 5 дней назад

    Understood Bhai

  • @heavenlyway5824
    @heavenlyway5824 Год назад +16

    I appreciate everything you're doing. However, my only suggestion is, can you keep dark mode while writing code.

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

    Bhaiya u got the ipad and you are great at explaining things..but its too tough to explain in interview in such a pressure situation😢

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

      But try to give all the approach it will be the edge factor in the interview

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

    Understood

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

    Absolutely loving your SDE sheet ….please just make a video on Rabin Karp algo and KMP algo…thoda bouncer jara hai uska concepts.

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

      Where can I find it ?

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

      @@grette4156 search on google-striver sde sheet

  • @project_eth
    @project_eth 28 дней назад

    holy sh*t this question was hard to understand, but seriously man what an explanation!

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

    Sir please add videos for linked list 😄

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

    bhaiya ....some game changer was coming on 22nd july

  • @anupamtiwary4265
    @anupamtiwary4265 25 дней назад

    thank you

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

    Sir please upload strings lectures❤❤🎉❤❤

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

    True to your name, Striver.

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

    Bayya please make sure in SDE sheet the you tube video should be play in other page when we click to watch

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

    Op❤🔥

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

    Instead of checking if the mid exactly divides arr[i+1]-arr[i] or not, we can directly do ceil((arr[i+1]-arr[i]) / mid) - 1 to avoid that issue.

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

    Hi, Striver I had asked you in your previous videos when to use while(high-low>1) like conditions. Put some light on it.🙂

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

      I said repeatedly, we solve all the problems with while(low

  • @sanjayp.m7008
    @sanjayp.m7008 Год назад +2

    why is the site of takeyouforward down?? please fix it as soon as possible as many are using sde sheet and a2z sheet form there

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

    Before Optimizing this with BS It was preety Easy to Solve but When it comes to furthur optimize,
    the question changes it's difficulty to Hard
    Nicely Explained
    Thank You Bhai

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

    problem: You have a list of numbers that are sorted in increasing order. You also have two numbers, K and X. Your task is to find the K numbers in the list that are closest to X. If two numbers are equally close to X, you should choose the smaller one.
    For example, if the list A is [2, 6, 7, 10] and K is 2 and X is 8, then the closest numbers to 8 are 7 and 6.
    Hi. Could you create a binary search video for this "K closest element problem".😶
    ps: I have been following your binary search playlist and I am happy that I found exact pattern of updating low, mid and high for all the problems. But in the above problem is there a way to follow the same binary search pattern?
    I have seen many videos on youtube but everywhere they are updating high = mid and while condition is also different. It is like while(low

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

    Bhaiya needs more stuff

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

    I dont think we need the line
    if((arr[i] - arr[i-1]) == (dist * numberInBetween)) {
    numberInBetween--;
    }
    Beacause even if you remove this line of code, the code gets submitted. I think this is because if we dont have this line, the cnt will be overestimated and so it will automatically execute low=mid and in doing so, it will further execute the high=mid calls and we will reach a answer closer to the actual ans with diff less than 1e-6

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

    bhaiya jo aapne website par arrays ki playlist ke upar brute force, better and optimal solution ka new feature ek hee page par diya hai. bss hame column par click karna hoga woh feature baaki playlists par bhi apply kar dijiye. Tree, Graph, aur DP abhi purane feature ke hisaab se he hai.

  • @shreyanshtiwari6530
    @shreyanshtiwari6530 11 месяцев назад +3

    Sir what do you suggest if i am able to solve question from your sheet after looking at some part of videos or some discussion section of leetcode i mean i am not able to solve new questions by myself but after learning i am able to solve thosr types . So i was just wondering whether its right to look up at the solutions and learn from it or should give more time to solve questions by myself only ? Its a honest question i wish you can answer.

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

      same case with me...i think we should just solve more and more problems(by looking at solution) until we get used to the pattern of solving the questions!

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

    understood :)

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

    understood 😇