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
My bad, a small correction in the code:
if((arr[i] - arr[i-1]) == (dist * numberInBetween)) {
numberInBetween--;
}
1 == (2 * 0.5)
bhai gfg ki link striver A2Z me add karo plz striver sheet is incomplete without gfg
I am confused.. how it is passing all the test cases then? By the way, Great Explanation love it😇
@@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.
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.
if(fmod((long double)(arr[i+1]-arr[i]),mid)==0) numberInBetween--;
modulus work only in case of int so fmod
Striver is trying his very best to explain but the problem itself is very complex. Hats off bro...
What a noble man. May he achieve all the success that he wants
he had already achieved it
@@sohamgaikwad15 still more go
Sir please continue the series ...a lot of students are waiting eagerly for your videos .
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.
Guys those of you saying use low
I think all almost all of them😅
@@infinityzero2321 yes bro
please explain here only, I don't have time to go through whole playlist
@@GeneralistDev nhi bateynege poora dekh
@@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.
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..........🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
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
Hard problem to absorb...! Kudos to your efforts, hats off Striver for your dedication
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.
Dedication, Made Respect to him!! GIving a complete insight on the topic is just insane and very few people do it!
Understood! Super amazing explanation as always, thank you very much for your effort!!
The best DSA course on the Internet
Effort level:- Inspirational 🏆
UNDERSTOOD...........Thank You So Much for this wonderful video..............🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
Amazing explanation so far🔥
Amazing! Dedication is super! Thank you Striver!
Can't thank you enough for this amazing content!! Explained so perfectly!! Thank you Striver for this course!!
Thank you so much Striver.Loved it.💖
no one explains better than you ,thank you
Thank you for explaining this difficult question so brilliantly.
Very well understood all three approaches specially priority queue one method
Great Approach. Really loved the explanation. You made such an hard question easy to understand. Thanks❤❤
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.
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 :)
hats off to your efforts sir, very well explained
Awesome explanation. still trying to absorb last approach
UnderStood Striver, and that's awesome. Thanks for making this
just wow.. u really inspire me sir..
Hats off to the explanation. Awesome work sir
Great video sir! Hats off!
Thank You Striver for the best explaination
Best explanation! this was my first hard problem, but you made it so easy to understand. Hats off bhaiya!!!!
This surely is an amazing problem
Done! Nicely explained
Hats off to your hardwork brother 🤍🫡
sir ek hi dil hai kitne baar jeetoge ❣
I would rather fail interview than trying this binary search solution
took me 3 hours to make through this video
Amazing content bro... Love you so much
His efforts>>>>
you're doing great job
Good explanation, please start string then linkedlist, also please add gfg links
maybe high have to watch again after sometime awesome video
Hats off to your hard work 🫡
You are just awesome man👍
keep up the good work bro...
Striver bhai plzz start string series i am waiting for it.... ❤️❤️❤️
THANKU SO MUCH SIR!!! LOVE U MAN
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
Yes pls 😊
yes
Yesss please Striver
Why are the videos not coming? please make a video regarding when the future videos will be released. I am very excited.
you are great bhaiya love you❤
best video till date
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!!
did this question even before watching video. you taught binary search so good that I was able to do it so easily
NICE VIDEO UNDERSTOOD !!!
Very nice explanation
Madddd Respect man♥♥
From Bruteforce -> better -> optimal. It was really hard question in BS. But anyways Thank You Striver for best explanation.
last wali ne dimaag hila daala bhai!!
Understood✅🔥🔥
Sir pls continue the series..
please striver post the next videos asap we are eagerly waiting for ur vds please, placement start ho gya please complete the series
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
final year aswell?
Super❤🔥
Striver you are GOD!!!
Understoood!!!!!
A small improvement in brute force is u don't need to have a howmany vector u can use the pair in pq
Bhai Will You Continue To Upload DSA COURSE VIDEOS AFTER BINARY SEARCH??? PLEASE UPLOAD STRING PLAYLIST BHAI
Stack & Queue Series Please Also Linked List.
Bhai please continue the series
Thanks.Understood
Thank you Bhaiya
Subscribed Nice👌
Plz bhaiya upload more and more videos as soon as possible......plz bhaiya
Th ode question khud se bhi try kiya karo 🥲
@@Daddy30011 not question bro.....I say introduction tutorial of pointer and some other
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 🥺
bhai can yu tell how many month yu will take complete this course actually i am new this chanel approx 3 month
Understood Bhai
I appreciate everything you're doing. However, my only suggestion is, can you keep dark mode while writing code.
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😢
But try to give all the approach it will be the edge factor in the interview
Understood
Absolutely loving your SDE sheet ….please just make a video on Rabin Karp algo and KMP algo…thoda bouncer jara hai uska concepts.
Where can I find it ?
@@grette4156 search on google-striver sde sheet
holy sh*t this question was hard to understand, but seriously man what an explanation!
Sir please add videos for linked list 😄
bhaiya ....some game changer was coming on 22nd july
whats that
thank you
Sir please upload strings lectures❤❤🎉❤❤
True to your name, Striver.
Bayya please make sure in SDE sheet the you tube video should be play in other page when we click to watch
Op❤🔥
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.
Hi, Striver I had asked you in your previous videos when to use while(high-low>1) like conditions. Put some light on it.🙂
I said repeatedly, we solve all the problems with while(low
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
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
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
solve this using heap
@@iWontFakeIt yes but there is binary search solution for thi as well
Bhaiya needs more stuff
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
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.
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.
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!
understood :)
understood 😇
again understood