BS-17. Aggressive Cows | Binary Search Hard

  Рет қаралды 175,600

take U forward

take U forward

Күн бұрын

Пікірлер: 269
@sus_tha_coder
@sus_tha_coder Жыл бұрын
Aggressive striver
@shreyasingh1960
@shreyasingh1960 Жыл бұрын
😂😂😭
@SuyashKumar-fd7gl
@SuyashKumar-fd7gl 4 ай бұрын
😂
@satvick_ahuja7
@satvick_ahuja7 2 ай бұрын
😂😂😂
@rohitverma1057
@rohitverma1057 10 ай бұрын
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)
@abhaychoudhary6746
@abhaychoudhary6746 2 ай бұрын
but for this you need to traverse the array
@Aryan_o7
@Aryan_o7 2 ай бұрын
@25:13 @rohitverma1057
@technicalteam3298
@technicalteam3298 Жыл бұрын
you are "The" best teacher In terms of explanation I have tried many KZbinrs 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 Жыл бұрын
Series from Kunal are incomplete. Even after recent updates, its quite far from completion.
@albedo9617
@albedo9617 5 ай бұрын
Neetcode is pretty good
@rickk3300
@rickk3300 5 ай бұрын
@@albedo9617 yes
@Josuke217
@Josuke217 4 ай бұрын
Exactly, Babbar hasn't covered topics in depth . Kunal of course hasn't completed the course
@himanshurane4847
@himanshurane4847 Жыл бұрын
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
@341yes
@341yes Жыл бұрын
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!❤
@manojkumar-hr7tj
@manojkumar-hr7tj 27 күн бұрын
Just by looking at the comments, I wanted to give a try and got succeeded. Thanks Striver!!!
@Bigg_boss_trolls
@Bigg_boss_trolls 2 күн бұрын
you are "The" best teacher In terms of explanation
@AkshayGoel-of8ic
@AkshayGoel-of8ic Жыл бұрын
I searched for aggressive cow solution and i got you THE BEST EXPLANATION
@devgarg4331
@devgarg4331 9 ай бұрын
coded optimal in one go , without seeing video 😀 . THANKS A LOT STRIVER FOR EVERYTHING
@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❤
@lavanya_m01
@lavanya_m01 7 ай бұрын
After reading the problem statement, I didn't even understand it. It is crystal clear after watching your explanation! Thanks Striver :)
@reshmah1497
@reshmah1497 19 күн бұрын
Very good explanation Striver! Thanks a lot for these teachings. These are a great source of knowledge for tier-4 colleges too.
@visase2036
@visase2036 Жыл бұрын
I have been asked a similar question when i appeared for Google , the question was : The city is affected with Covid 19 and hospitals are filling up with patients. As a doctor , you need to make sure the patients are treated well. To do so You have some patients and beds for them to be allocated and the survival rate of the patients will be higher only if they are placed as far as possible. Given m beds and n patients maximize the minimum distance between any two patients to increase the survival rate. Ans : Same Binary Search approach .
@kartikeyrana3736
@kartikeyrana3736 Жыл бұрын
were you selected ?
@visase2036
@visase2036 Жыл бұрын
@@kartikeyrana3736 yes , but no :). Moved to the next rounds but on hold due to hiring freeze!
@munvut877
@munvut877 10 ай бұрын
this question is same as this!
@elizabethr5161
@elizabethr5161 Жыл бұрын
Clearly Understood Striver. Thanks for this awesome series.
@aniketwdubey
@aniketwdubey Жыл бұрын
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 10 ай бұрын
Ya you can write but it wont make any difference in the time taken... The change in time taken is less than 1ms
@ujjawalraj6096
@ujjawalraj6096 Жыл бұрын
Understand everything Min Of Max pattern super duper clear
@pradipkumarmukhi
@pradipkumarmukhi Ай бұрын
Grateful beyond words, Striver! You transformed the Aggressive Cows problem from a daunting challenge to a clear solution. Your explanation not only sharpened my DSA skills but also boosted my confidence in problem-solving. Huge thanks for your patience and precision!❤❤
@52nevil36
@52nevil36 Жыл бұрын
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)
@aaryanjavalekar7249
@aaryanjavalekar7249 Жыл бұрын
The best explanation for Aggressive Cows problem!
@priyanshigusain6722
@priyanshigusain6722 2 ай бұрын
i am really really really X 100000 speechless he is am amazing teacher means he makes the problem look like it's nothing i have never met such simplified teacher you are serendipity encounter for me😇😇🤩🤩🤩.
@NonameNoname-f2t
@NonameNoname-f2t 9 ай бұрын
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.
@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 Жыл бұрын
That's the main problem bro.
@bishalkundu7592
@bishalkundu7592 Жыл бұрын
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 7 ай бұрын
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 7 ай бұрын
@@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 6 ай бұрын
@@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.
@CodeMode9313
@CodeMode9313 Жыл бұрын
Habibi issme thoda mushkil hua samjne me but dimak lagai toh samaj aagai ....tusssi ek number kaam karta hai ...acchi bideo banaata hai
@rintugayen2435
@rintugayen2435 4 ай бұрын
Hanuman chalisa padhke iss lecture ko dekh samajh aa jayega
@RaunitJaiswal-s9v
@RaunitJaiswal-s9v 2 ай бұрын
😂​@@rintugayen2435
@PriyamJamwal
@PriyamJamwal 4 ай бұрын
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
@stith_pragya
@stith_pragya 9 ай бұрын
UNDERSTOOD...Thank You So Much for this wonderful video.............🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
@venkatamurthy6022
@venkatamurthy6022 Жыл бұрын
Your explanation is so clear that even beginners can also understand easily.
@revanthchouhan3068
@revanthchouhan3068 3 ай бұрын
Man, you're built different. You make everything understandable! Keep doing the same
@sxd6259
@sxd6259 Жыл бұрын
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
@shaikkhizar8133
@shaikkhizar8133 9 ай бұрын
Super Sir Understood Thankyou for this Lecture
@souvikbiswas284
@souvikbiswas284 2 ай бұрын
I understood the question at 07:20 and coded the answer. The question is almost similar to "Find the smaller divisor". All thanks to you Striver, your explanation of the approach has helped me to come up with the answer on my own.. 😍😍❤❤
@souvikbiswas284
@souvikbiswas284 2 ай бұрын
Here's the Solution: class Solution: def aggressiveCows(self, nums, k): nums.sort() n = len(nums) l = 0 r = nums[-1] - nums[0] while l > 1) cows_placed = 1 last_pos = nums[-1] for curr in range(n-2, -1, -1): if last_pos - nums[curr] >= distance: cows_placed += 1 last_pos = nums[curr] if cows_placed >= k: break if cows_placed < k: r = mid - 1 return r
@Video-Notes
@Video-Notes 6 ай бұрын
Best Explanation ............... Best Course on youtube
@pushpendrasingh777
@pushpendrasingh777 2 ай бұрын
I coded it on my own after you explained the approach
@arjunthakur5827
@arjunthakur5827 8 ай бұрын
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
@manitoshpaul6170
@manitoshpaul6170 5 ай бұрын
Is it only me or any one else have also felt that the binary search medium problems are a bit doable rather than the easy problems... They seem to be hard. However, doesn't this problem seems to be a. 90% similar to minimum days to ship d packages or m bouquet flowers problem.
@graviton001
@graviton001 3 ай бұрын
Yes I find all medium problems quiet similar 😅 and I did it myself
@Fe-ironman
@Fe-ironman Ай бұрын
5-10 were most difficult after that most were easy
@farheenahmed8286
@farheenahmed8286 5 ай бұрын
The best explanation for aggressive cows problem🙂
@simransaini1227
@simransaini1227 4 ай бұрын
Understood !!!!! Grateful of you, Striver🙏
@samsmith3961
@samsmith3961 Жыл бұрын
since we have to min of max distance we'll have to find divide the distances as equal as possible , then choose the minimum
@patilrajesh2500
@patilrajesh2500 Ай бұрын
Lecture successfully completed on 22nd October 2024🔥🔥
@cinime
@cinime Жыл бұрын
Understood! Super amazing explanation as always, thank you so so much for your continuous effort!!
@darrienxavier5536
@darrienxavier5536 3 ай бұрын
In the Brute Force approach return i-1 won't work in all cases , we could use a variable to keep track of the distance and then return it
@rohakdebnath8985
@rohakdebnath8985 11 ай бұрын
Loved the video. I was stuck in this problem. You have a way with explanations, thanks Striver.
@AK-nj1je
@AK-nj1je 8 ай бұрын
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.
@Manishgupta200
@Manishgupta200 Жыл бұрын
Taking high and low is logical and tricky to solve porblem in much more optimal way
@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 Жыл бұрын
woh sirf lagta hai, new problem try karo
@ShobhitRaghuwanshi-lx2nt
@ShobhitRaghuwanshi-lx2nt 4 ай бұрын
​@@varunaggarwal7126 true 😂
@sushantguria8820
@sushantguria8820 24 күн бұрын
What a great explanation, thank you sir
@rajveersingh2056
@rajveersingh2056 Жыл бұрын
Farthest would be (max - min) / (cows - 1)
@naveensingh596
@naveensingh596 Жыл бұрын
Understood...so simple explanation bhaiya💙
@PrajwalCoding
@PrajwalCoding 11 ай бұрын
Heyyy, Thanks for the polarity change explanation. I was shocked understanding the intution
@debanjanghosal618
@debanjanghosal618 Ай бұрын
This is a max(min) problem. This is because we are maximizing the minimum distance between any two cows.
@samarthpai5359
@samarthpai5359 20 күн бұрын
Wonderful explaination! understood
@AtulKumar-c4x7l
@AtulKumar-c4x7l Жыл бұрын
understood Thank you striver for such an amazing explanation
@MaheshPatil-of1zy
@MaheshPatil-of1zy 2 ай бұрын
in the brute force approach the time complexity of the sorting is not included.
@rishabh1S
@rishabh1S Жыл бұрын
Not gonna lie, Binary search made it look so simple.
@umairislam8715
@umairislam8715 23 күн бұрын
You are amazing Striver❤
@krishnasharma-rn3sd
@krishnasharma-rn3sd 4 ай бұрын
clearly understood bro .awesome explanation!!!
@kaichang8186
@kaichang8186 Ай бұрын
understood, thanks for the perfect explanation
@shashikumar2382
@shashikumar2382 9 ай бұрын
Just amazing content , I was unable to understand the question but now i am able to solve it. 💌💌💌🤟
@Sahilsharma-sk5vr
@Sahilsharma-sk5vr 5 ай бұрын
your dedication . god bless you
@samreenimam8608
@samreenimam8608 10 ай бұрын
yes yes, still watching and iked.. tysm
@RobinSingh-nf4oo
@RobinSingh-nf4oo 2 ай бұрын
explanation on top🔥🔥🔥🔥
@nihaal4699
@nihaal4699 7 ай бұрын
Bht hi badiya padaya bhai, maja agya
@ritwik121
@ritwik121 Жыл бұрын
someone give him a oscar for the best explanation
@varun_immadisetti
@varun_immadisetti Ай бұрын
crystal clear sir
@Musicuvakavi1823
@Musicuvakavi1823 7 ай бұрын
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
@bhagyashreekhairnar683
@bhagyashreekhairnar683 9 ай бұрын
Thank you! Lots of gratitude 🌸
@shantipriya370
@shantipriya370 11 ай бұрын
superb explanation
@hareshnayak7302
@hareshnayak7302 7 ай бұрын
Understood,Thanks striver for this amazing video.
@chetnaraghav9979
@chetnaraghav9979 11 күн бұрын
Thank you Striver
@abdulrhmanmagdy7591
@abdulrhmanmagdy7591 Жыл бұрын
Thank u so much, u are very helpful greeting from Egypt
@dayashankarlakhotia4943
@dayashankarlakhotia4943 Жыл бұрын
Understood very good explanation than previous explanation
@GauravJain-zo8gt
@GauravJain-zo8gt 5 ай бұрын
jai jinendra sir
@satwiksrivastava
@satwiksrivastava 4 ай бұрын
Today this problem was asked in Salesforce intern OA with the name of fighting children 😂 The joy of mapping the algorithm.
@DM2K6
@DM2K6 3 ай бұрын
almost did on my own. thanks striver
@javabytharun
@javabytharun 4 ай бұрын
great explanation, easily understood...............
@faizanahmed9304
@faizanahmed9304 Жыл бұрын
19:01 we are sorting as well. O(nlogn)
@prathameshthorat9350
@prathameshthorat9350 4 ай бұрын
Similar Question on Leetcode : 1552. Magnetic Force Between Two Balls
@usmankhatri6836
@usmankhatri6836 Жыл бұрын
Striver! What's next after this amazing BS Playlist?
@priyankaranawat8373
@priyankaranawat8373 5 ай бұрын
Thank you soooooooo much 😁
@aruna5869
@aruna5869 5 ай бұрын
you are extradinary man!!💛💯
@alishashaikh3859
@alishashaikh3859 Жыл бұрын
Hello Striver,I am not able to solve the problems on my own what should i do?
@sauravkumarjha6162
@sauravkumarjha6162 Жыл бұрын
amazing explanation as always striver bhaiya
@dhruvmalik8052
@dhruvmalik8052 Жыл бұрын
great Explanation luv u brother
@dipingrover1970
@dipingrover1970 5 ай бұрын
amazing explanation thanks a lot .😊
@culeforever5408
@culeforever5408 Жыл бұрын
understood 😇
@Shunya_Advait
@Shunya_Advait Жыл бұрын
Understood Sir, Thank you
@VishalGupta-xw2rp
@VishalGupta-xw2rp Жыл бұрын
22:05 Opposite Polarity
@ishangujarathi10
@ishangujarathi10 Жыл бұрын
best explanation and intuition
@MJBZG
@MJBZG 4 ай бұрын
amazing question!
@crazymemes4080
@crazymemes4080 3 ай бұрын
i am preparing for offcampus :) thank you for everything.
@oyeesharme
@oyeesharme 3 ай бұрын
understood bhaiya
@ashfakahamed9266
@ashfakahamed9266 Жыл бұрын
If "Find min or find max" is what you will use to identify Binary Search then eventually you will get stuck in the DP problems
@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!!
@arunsagarsa3613
@arunsagarsa3613 4 ай бұрын
@takeUforward The moment I get my job with this channels' help, I shall thank you and join the KZbin channel.
@rockykumarverma980
@rockykumarverma980 2 ай бұрын
Thank you so much sir🙏🙏🙏
@VarshaSingh-hi2sb
@VarshaSingh-hi2sb 2 ай бұрын
Why we are always placing the cow at first index only. There can be combinations where placing at first and all cows are placed then also places would be left to place more cows . So it is also possible that if we started from positon other than first it might have possible to place all the cows so why always position 1?
@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
@shra1
@shra1 Жыл бұрын
Understood very well
@kallabhargavi-d7j
@kallabhargavi-d7j 7 ай бұрын
understood striver
@joeljacob4685
@joeljacob4685 Жыл бұрын
Understood !! Beautifully explained
@neerajnegi1958
@neerajnegi1958 11 күн бұрын
Understood ❤️❤️
BS-18. Allocate Books or Book Allocation | Hard Binary Search
27:29
take U forward
Рет қаралды 183 М.
Из какого города смотришь? 😃
00:34
МЯТНАЯ ФАНТА
Рет қаралды 2,5 МЛН
What type of pedestrian are you?😄 #tiktok #elsarca
00:28
Elsa Arca
Рет қаралды 32 МЛН
#Rasmika mandana #pushpa2 treler #youtubeshorts #youtubeshorts
0:42
Bihari patel 120
Рет қаралды 98 М.
3 Types of Algorithms Every Programmer Needs to Know
13:12
ForrestKnight
Рет қаралды 500 М.
3 Sum | Brute -  Better - Optimal with Codes
38:25
take U forward
Рет қаралды 352 М.
BS-13. Minimum days to make M bouquets | Binary Search
26:01
take U forward
Рет қаралды 152 М.
BS-16. Kth Missing Positive Number | Maths + Binary Search
22:52
take U forward
Рет қаралды 158 М.
Quick Sort For Beginners | Strivers A2Z DSA Course
35:17
take U forward
Рет қаралды 454 М.
Mastering Dynamic Programming - How to solve any interview problem (Part 1)
19:41
Из какого города смотришь? 😃
00:34
МЯТНАЯ ФАНТА
Рет қаралды 2,5 МЛН