BS-17. Aggressive Cows | Binary Search Hard

Problem Link: bit.ly/3J9ab1B
Notes/C++/Java/Python codes: Soon
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

Пікірлер: 211

  • @sus_tha_coder
    @sus_tha_coder Жыл бұрын

    Aggressive striver

  • @shreyasingh1960

    @shreyasingh1960

    Жыл бұрын

    😂😂😭

  • @SuyashKumar-fd7gl

    @SuyashKumar-fd7gl

    16 күн бұрын

    😂

  • @technicalteam3298
    @technicalteam329811 ай бұрын

    you are "The" best teacher In terms of explanation I have tried many KZreadrs like Codehelp, kunal kushwaha but your way of explaining things is much better as you focus on approach not only on coding the things without visualizing possibilities may god bless you for helping many Tier 3 students like me for providing this premium content just for free!

  • @anshulgoel1940

    @anshulgoel1940

    10 ай бұрын

    Series from Kunal are incomplete. Even after recent updates, its quite far from completion.

  • @albedo9617

    @albedo9617

    Ай бұрын

    Neetcode is pretty good

  • @rickk3300

    @rickk3300

    Ай бұрын

    @@albedo9617 yes

  • @341yes
    @341yes10 ай бұрын

    This man is magic when comes to a certain set of problems!!!.... Simply, impressed by him! The explanation easily depicts how much hardwork he has put in! HandsOff to you sir!❤

  • @harshpanwar1550
    @harshpanwar1550 Жыл бұрын

    You win our hearts in every video, specially the hard problems by explaining them in such a beautiful and simple manner. Thank you for your enormous contributions toward the Coding Community❤

  • @lavanyam3224
    @lavanyam32243 ай бұрын

    After reading the problem statement, I didn't even understand it. It is crystal clear after watching your explanation! Thanks Striver :)

  • @AkshayGoel-of8ic
    @AkshayGoel-of8ic Жыл бұрын

    I searched for aggressive cow solution and i got you THE BEST EXPLANATION

  • @himanshurane4847
    @himanshurane48479 ай бұрын

    I solved this question just after you explained the question, and this is because you explained previous questions so well, and this is the power of your teaching

  • @elizabethr5161
    @elizabethr5161 Жыл бұрын

    Clearly Understood Striver. Thanks for this awesome series.

  • @cinime
    @cinime Жыл бұрын

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

  • @user-ik3qu5uy5e
    @user-ik3qu5uy5e4 ай бұрын

    I am getting crazy with every next video full of excitement and respect for you. How easy , clean , structured the problem and its solution . Best part when the complete story ends with code same as the story we listen, we read it too by the code.

  • @rohitverma1057
    @rohitverma10576 ай бұрын

    13:24 like he says that range can be optimized. The more optimal lower bound for search space will be the Minimum(adjacent difference). Reason: Let's take array [100, 200, 240, 400, 800]. In this 40 would be the lower bound and not starting from 1. Because if you want to place minimum 2 cows (like question says). You cannot attain difference any lower than this in sorted array which is 40 in this case i.e. Minimum(adjacent difference)

  • @devgarg4331
    @devgarg43315 ай бұрын

    coded optimal in one go , without seeing video 😀 . THANKS A LOT STRIVER FOR EVERYTHING

  • @aaryanjavalekar7249
    @aaryanjavalekar7249 Жыл бұрын

    The best explanation for Aggressive Cows problem!

  • @CodeMode9313
    @CodeMode931311 ай бұрын

    Habibi issme thoda mushkil hua samjne me but dimak lagai toh samaj aagai ....tusssi ek number kaam karta hai ...acchi bideo banaata hai

  • @rohakdebnath8985
    @rohakdebnath89857 ай бұрын

    Loved the video. I was stuck in this problem. You have a way with explanations, thanks Striver.

  • @venkatamurthy6022
    @venkatamurthy6022 Жыл бұрын

    Your explanation is so clear that even beginners can also understand easily.

  • @simransaini1227
    @simransaini122721 күн бұрын

    Understood !!!!! Grateful of you, Striver🙏

  • @PrajwalCoding
    @PrajwalCoding7 ай бұрын

    Heyyy, Thanks for the polarity change explanation. I was shocked understanding the intution

  • @sxd6259
    @sxd625911 ай бұрын

    i think you should also optimise the check function a bit more by using lowerbound instead of linear search for the next cow stall index, great solution thought

  • @stith_pragya
    @stith_pragya5 ай бұрын

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

  • @ujjawalraj6096
    @ujjawalraj6096 Жыл бұрын

    Understand everything Min Of Max pattern super duper clear

  • @user-ti3bd8mp1w
    @user-ti3bd8mp1w Жыл бұрын

    understood Thank you striver for such an amazing explanation

  • @52nevil36
    @52nevil369 ай бұрын

    Genereally i never do any comment to video but the guys was insane.. this made DSA too easy for mr (I feel slowly slowly DSA is cup of my v tea)

  • @Video-Notes
    @Video-Notes2 ай бұрын

    Best Explanation ............... Best Course on youtube

  • @ishangujarathi10
    @ishangujarathi10 Жыл бұрын

    best explanation and intuition

  • @krishnasharma-rn3sd
    @krishnasharma-rn3sd21 күн бұрын

    clearly understood bro .awesome explanation!!!

  • @naveensingh596
    @naveensingh5969 ай бұрын

    Understood...so simple explanation bhaiya💙

  • @srikanthmedicherla4841
    @srikanthmedicherla4841 Жыл бұрын

    Aggressive understood lol. Great explanation striver!

  • @bhagyashreekhairnar683
    @bhagyashreekhairnar6835 ай бұрын

    Thank you! Lots of gratitude 🌸

  • @aruna5869
    @aruna5869Ай бұрын

    you are extradinary man!!💛💯

  • @rickk3300
    @rickk3300 Жыл бұрын

    I solved this question without watching the video just because of the fact that I knew that binary search on answers is going to be applied here, but my question is that how the hell can someone come up with the binary search approach if he/she doesn't know that it is going to be solved using binary search. When I first read this question, the first thought that came to my mind was applying dp.

  • @utsavseth6573

    @utsavseth6573

    11 ай бұрын

    That's the main problem bro.

  • @bishalkundu7592

    @bishalkundu7592

    9 ай бұрын

    That's the thing which comes with practice. The more you practice, the more you will solve problems on different topics and you will be able to find patterns in it.

  • @ronakraj

    @ronakraj

    3 ай бұрын

    hey @techmaniac2002 now it has been 8 months since you said this and i think you might have practiced many questions since then, and so i wanted to know if you can now find the pattern and say that this question is going to be solved by this approach. or are you still struggling

  • @rickk3300

    @rickk3300

    3 ай бұрын

    @@ronakraj Nope, I haven't practiced many questions on DSA since I got placed in the month of August 🙂 I practically left DSA/CP since then...

  • @chetanraghavv

    @chetanraghavv

    2 ай бұрын

    @@ronakraj I think clear distinction between when to apply binary search or DP is that: whenever you observe that answer always lie between a fixed range, and you are getting an answer till a specific point and not getting any answer after a certain value (this is known as monotonic function) then for sure Binary Search can be applied. Whereas in DP, you will be asked to find the optimal answer (minimum or maximum, just like Binary Search) but the problem would be such that you HAVE TO explore all the answers and only after that determine optimal one, this is where recursion comes in which is used to explore all possibilities and finally overlapping subproblems in recursion are optimized using DP. But these things take time and practice.

  • @dayashankarlakhotia4943
    @dayashankarlakhotia4943 Жыл бұрын

    Understood very good explanation than previous explanation

  • @hareshnayak7302
    @hareshnayak73023 ай бұрын

    Understood,Thanks striver for this amazing video.

  • @nihaal4699
    @nihaal46993 ай бұрын

    Bht hi badiya padaya bhai, maja agya

  • @farheenahmed8286
    @farheenahmed8286Ай бұрын

    The best explanation for aggressive cows problem🙂

  • @samreenimam8608
    @samreenimam86086 ай бұрын

    yes yes, still watching and iked.. tysm

  • @javabytharun
    @javabytharun25 күн бұрын

    great explanation, easily understood...............

  • @sauravkumarjha6162
    @sauravkumarjha61629 ай бұрын

    amazing explanation as always striver bhaiya

  • @Sahilsharma-sk5vr
    @Sahilsharma-sk5vrАй бұрын

    your dedication . god bless you

  • @aniketwdubey
    @aniketwdubey8 ай бұрын

    In the context of this problem, you could also start with low = 1 since it doesn't make sense to have two rooms at the exact same position. The only reason to start with 0 is to provide a clear lower bound for the binary search. The result wouldn't be affected either way since the binary search would quickly discard unfeasible distances, but starting from 1 would be more intuitive in this context.

  • @soumojjalsen1915

    @soumojjalsen1915

    6 ай бұрын

    Ya you can write but it wont make any difference in the time taken... The change in time taken is less than 1ms

  • @abdulrhmanmagdy7591
    @abdulrhmanmagdy7591 Жыл бұрын

    Thank u so much, u are very helpful greeting from Egypt

  • @shashikumar2382
    @shashikumar23825 ай бұрын

    Just amazing content , I was unable to understand the question but now i am able to solve it. 💌💌💌🤟

  • @dipingrover1970
    @dipingrover1970Ай бұрын

    amazing explanation thanks a lot .😊

  • @dhruvmalik8052
    @dhruvmalik805211 ай бұрын

    great Explanation luv u brother

  • @manavsingh5919
    @manavsingh591910 ай бұрын

    thank you striver understood everything 🙂

  • @shaikkhizar8133
    @shaikkhizar81335 ай бұрын

    Super Sir Understood Thankyou for this Lecture

  • @sauravchandra10
    @sauravchandra10 Жыл бұрын

    Is binary search that easy, or is it the sriver effect? 😊

  • @myamazonproducts1683

    @myamazonproducts1683

    Жыл бұрын

    yes it obviously strivers effect.

  • @deeptidip9864

    @deeptidip9864

    Жыл бұрын

    Definately his effect💯💯

  • @varunaggarwal7126

    @varunaggarwal7126

    11 ай бұрын

    woh sirf lagta hai, new problem try karo

  • @ShobhitRaghuwanshi-lx2nt

    @ShobhitRaghuwanshi-lx2nt

    11 күн бұрын

    ​@@varunaggarwal7126 true 😂

  • @MJBZG
    @MJBZG21 күн бұрын

    amazing question!

  • @joeljacob4685
    @joeljacob46859 ай бұрын

    Understood !! Beautifully explained

  • @Shunya_Advait
    @Shunya_Advait10 ай бұрын

    Understood Sir, Thank you

  • @shra1
    @shra1 Жыл бұрын

    Understood very well

  • @priyankaranawat8373
    @priyankaranawat8373Ай бұрын

    Thank you soooooooo much 😁

  • @utsavseth6573
    @utsavseth657311 ай бұрын

    Well, That was lovely.

  • @ankitdhattarwal2286
    @ankitdhattarwal2286 Жыл бұрын

    Understood and Thank you

  • @usmankhatri6836
    @usmankhatri683611 ай бұрын

    Striver! What's next after this amazing BS Playlist?

  • @user-is6ky7pp2n
    @user-is6ky7pp2nАй бұрын

    Understood !! 😎😎

  • @user-or5oz1pk2x
    @user-or5oz1pk2x2 ай бұрын

    Thanks a lot Bhaiya

  • @varun1017
    @varun10175 ай бұрын

    superb explanation

  • @lakshmiprasanna7058
    @lakshmiprasanna7058 Жыл бұрын

    Understood 💯💯💯

  • @ritwik121
    @ritwik121 Жыл бұрын

    someone give him a oscar for the best explanation

  • @Musicuvakavi1823
    @Musicuvakavi18233 ай бұрын

    Understood well Sir ... Thank you so much Striver Sir for making such an amazing video... After understanding the problem, I was able to solve without seeing the code Thanks a lot Sir

  • @thenriquevicentini
    @thenriquevicentini2 ай бұрын

    Understood!

  • @YourCodeVerse
    @YourCodeVerse7 ай бұрын

    Understood✅🔥🔥

  • @aaronargottelopez3488
    @aaronargottelopez34882 ай бұрын

    Thanks!

  • @gauravbanerjee2898
    @gauravbanerjee28983 ай бұрын

    Thanks a lot

  • @Nimbus2k_rider
    @Nimbus2k_riderАй бұрын

    u r awesome...

  • @satwiksrivastava
    @satwiksrivastavaКүн бұрын

    Today this problem was asked in Salesforce intern OA with the name of fighting children 😂 The joy of mapping the algorithm.

  • @her_soulmate
    @her_soulmate6 ай бұрын

    Understood 🎉

  • @PriyamJamwal
    @PriyamJamwal17 күн бұрын

    based on AP, to optimize further you can set high = ceil((double)(stall[n-1] - stall[0]) / (double)c) stall is array of sorted stalls, c is no. of cows

  • @samsmith3961
    @samsmith396111 ай бұрын

    since we have to min of max distance we'll have to find divide the distances as equal as possible , then choose the minimum

  • @PriyankaSingh-sl2wg
    @PriyankaSingh-sl2wg8 ай бұрын

    Thank you sir.....❤️

  • @AK-nj1je
    @AK-nj1je4 ай бұрын

    You're seriously a legend 🔥🔥🔥 you made me consistent to dsa Thanks a lot❤ Those who cannot find this question on leetcode, there's a question as 1552. Magnetic Force Between Two Balls which is as same as this you can do that.

  • @harshitjaiswal9439
    @harshitjaiswal943911 ай бұрын

    Understoooooooooooooood!

  • @culeforever5408
    @culeforever54088 ай бұрын

    understood 😇

  • @Manishgupta200
    @Manishgupta200 Жыл бұрын

    Taking high and low is logical and tricky to solve porblem in much more optimal way

  • @googleit2490
    @googleit2490 Жыл бұрын

    Understood:)

  • @arihantjammar8888
    @arihantjammar888811 ай бұрын

    UNDERSTOOD

  • @harshilpatel3205
    @harshilpatel32055 ай бұрын

    Understood sir 😉🤍

  • @ayushagarwal5271
    @ayushagarwal5271Ай бұрын

    In the canweplace func, is it okay to do if(cntcows==cows) return true, rather than >= ?

  • @Chandraprakash-kx4ic
    @Chandraprakash-kx4ic Жыл бұрын

    #best #explnation

  • @GauravJain-zo8gt
    @GauravJain-zo8gtАй бұрын

    jai jinendra sir

  • @anand_yv
    @anand_yv10 ай бұрын

    Understood

  • @manishkaushik6526
    @manishkaushik652610 ай бұрын

    but for the first approach it is neccessary to sort ?

  • @alishashaikh3859
    @alishashaikh38599 ай бұрын

    Hello Striver,I am not able to solve the problems on my own what should i do?

  • @faizanahmed9304
    @faizanahmed9304 Жыл бұрын

    19:01 we are sorting as well. O(nlogn)

  • @pihus3498
    @pihus3498 Жыл бұрын

    understoodd :)

  • @adgaur090
    @adgaur09010 ай бұрын

    understood sir

  • @rishabh1S
    @rishabh1S11 ай бұрын

    Not gonna lie, Binary search made it look so simple.

  • @rohanpathak
    @rohanpathak Жыл бұрын

    Bhaiya thanku for the course,but kab tk complete hoga?pls tell

  • @ad_akshat
    @ad_akshat5 ай бұрын

    can we do it like this place one cow in start one cow at thee end and then think something like that??

  • @shreyasingh1960
    @shreyasingh1960 Жыл бұрын

    Sir compang will start coming within a month, please upload all the most imp question whivh uou have still not uploaded, topics/question will u think are more important than others!!

  • @ishaanchandak4774
    @ishaanchandak477410 ай бұрын

    can we do it using dp i tried it but wasn't getting the correct ans

  • @zooomba62
    @zooomba626 ай бұрын

    what about the time complexity of sorting ? we need to add it right ?

  • @amit2197kumar
    @amit2197kumar12 күн бұрын

    Can anyone help me understand why we need to sort the array of stalls in the first place? Thanks.

  • @arjunthakur5827
    @arjunthakur58274 ай бұрын

    My approach sort the array, create an array arrd with difference between consecutive elemnts of the array, if k==2 asign first and last (max distance) if more in arrd, sort it pop until k, the last k poped gives min distance

  • @devchangela8379
    @devchangela8379 Жыл бұрын

    understood

  • @rahulbhagat4023
    @rahulbhagat402311 ай бұрын

    why is it necessary to fix the first cow at the first position?

  • @user-js1rx8rs9p
    @user-js1rx8rs9p3 ай бұрын

    understood striver

  • @trixxy8304
    @trixxy8304 Жыл бұрын

    Don't we need to sort the array in linear search too? It should add an extra nlogn to the time complexity right?

  • @takeUforward

    @takeUforward

    Жыл бұрын

    Yes small things, you are smart now ;)

  • @shreyasingh1960

    @shreyasingh1960

    Жыл бұрын

    ​@@takeUforwardaww

  • @hamzarehman7057
    @hamzarehman7057 Жыл бұрын

    Sir I had a query. Since I'm learning DSA for the first time. Should I solve the easy questions of all topics and then move to their medium and hard questions. or study a topic like easy>medium>hard and then next topic?

  • @ganakkathuria3645

    @ganakkathuria3645

    Жыл бұрын

    Solve easy ones , once you have done around 50-60 easy questions then move to