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
Aggressive striver
@shreyasingh1960
Жыл бұрын
😂😂😭
@SuyashKumar-fd7gl
16 күн бұрын
😂
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
10 ай бұрын
Series from Kunal are incomplete. Even after recent updates, its quite far from completion.
@albedo9617
Ай бұрын
Neetcode is pretty good
@rickk3300
Ай бұрын
@@albedo9617 yes
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!❤
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❤
After reading the problem statement, I didn't even understand it. It is crystal clear after watching your explanation! Thanks Striver :)
I searched for aggressive cow solution and i got you THE BEST EXPLANATION
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
Clearly Understood Striver. Thanks for this awesome series.
Understood! Super amazing explanation as always, thank you so so much for your continuous effort!!
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.
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)
coded optimal in one go , without seeing video 😀 . THANKS A LOT STRIVER FOR EVERYTHING
The best explanation for Aggressive Cows problem!
Habibi issme thoda mushkil hua samjne me but dimak lagai toh samaj aagai ....tusssi ek number kaam karta hai ...acchi bideo banaata hai
Loved the video. I was stuck in this problem. You have a way with explanations, thanks Striver.
Your explanation is so clear that even beginners can also understand easily.
Understood !!!!! Grateful of you, Striver🙏
Heyyy, Thanks for the polarity change explanation. I was shocked understanding the intution
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
UNDERSTOOD...Thank You So Much for this wonderful video.............🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
Understand everything Min Of Max pattern super duper clear
understood Thank you striver for such an amazing explanation
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)
Best Explanation ............... Best Course on youtube
best explanation and intuition
clearly understood bro .awesome explanation!!!
Understood...so simple explanation bhaiya💙
Aggressive understood lol. Great explanation striver!
Thank you! Lots of gratitude 🌸
you are extradinary man!!💛💯
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
11 ай бұрын
That's the main problem bro.
@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
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
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
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.
Understood very good explanation than previous explanation
Understood,Thanks striver for this amazing video.
Bht hi badiya padaya bhai, maja agya
The best explanation for aggressive cows problem🙂
yes yes, still watching and iked.. tysm
great explanation, easily understood...............
amazing explanation as always striver bhaiya
your dedication . god bless you
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
6 ай бұрын
Ya you can write but it wont make any difference in the time taken... The change in time taken is less than 1ms
Thank u so much, u are very helpful greeting from Egypt
Just amazing content , I was unable to understand the question but now i am able to solve it. 💌💌💌🤟
amazing explanation thanks a lot .😊
great Explanation luv u brother
thank you striver understood everything 🙂
Super Sir Understood Thankyou for this Lecture
Is binary search that easy, or is it the sriver effect? 😊
@myamazonproducts1683
Жыл бұрын
yes it obviously strivers effect.
@deeptidip9864
Жыл бұрын
Definately his effect💯💯
@varunaggarwal7126
11 ай бұрын
woh sirf lagta hai, new problem try karo
@ShobhitRaghuwanshi-lx2nt
11 күн бұрын
@@varunaggarwal7126 true 😂
amazing question!
Understood !! Beautifully explained
Understood Sir, Thank you
Understood very well
Thank you soooooooo much 😁
Well, That was lovely.
Understood and Thank you
Striver! What's next after this amazing BS Playlist?
Understood !! 😎😎
Thanks a lot Bhaiya
superb explanation
Understood 💯💯💯
someone give him a oscar for the best explanation
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
Understood!
Understood✅🔥🔥
Thanks!
Thanks a lot
u r awesome...
Today this problem was asked in Salesforce intern OA with the name of fighting children 😂 The joy of mapping the algorithm.
Understood 🎉
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
since we have to min of max distance we'll have to find divide the distances as equal as possible , then choose the minimum
Thank you sir.....❤️
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.
Understoooooooooooooood!
understood 😇
Taking high and low is logical and tricky to solve porblem in much more optimal way
Understood:)
UNDERSTOOD
Understood sir 😉🤍
In the canweplace func, is it okay to do if(cntcows==cows) return true, rather than >= ?
#best #explnation
jai jinendra sir
Understood
but for the first approach it is neccessary to sort ?
Hello Striver,I am not able to solve the problems on my own what should i do?
19:01 we are sorting as well. O(nlogn)
understoodd :)
understood sir
Not gonna lie, Binary search made it look so simple.
Bhaiya thanku for the course,but kab tk complete hoga?pls tell
can we do it like this place one cow in start one cow at thee end and then think something like that??
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!!
can we do it using dp i tried it but wasn't getting the correct ans
what about the time complexity of sorting ? we need to add it right ?
Can anyone help me understand why we need to sort the array of stalls in the first place? Thanks.
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
understood
why is it necessary to fix the first cow at the first position?
understood striver
Don't we need to sort the array in linear search too? It should add an extra nlogn to the time complexity right?
@takeUforward
Жыл бұрын
Yes small things, you are smart now ;)
@shreyasingh1960
Жыл бұрын
@@takeUforwardaww
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
Жыл бұрын
Solve easy ones , once you have done around 50-60 easy questions then move to