BS-13. Minimum days to make M bouquets | Binary Search

  Рет қаралды 153,393

take U forward

take U forward

Күн бұрын

Пікірлер: 241
@udaykulkarni5639
@udaykulkarni5639 8 ай бұрын
5 mins into the video and I knew exactly how to code it up! Cheers man. This guy has some serious skills!
@shashankvashishtha4454
@shashankvashishtha4454 5 ай бұрын
That's candidate master for ya.
@anonymousanonymous7507
@anonymousanonymous7507 5 ай бұрын
gawd
@AyushSharma-sd1ny
@AyushSharma-sd1ny Жыл бұрын
Not a easy problem to understand directly by reading it.. Thanks you have made it very simple.
@adityarajvermaa
@adityarajvermaa Жыл бұрын
bro literally I coded it down myself...just came here to understand the problem coz it was too complex to understand. Now i can code medium range problems by myself....sooner or later I will be able to understand the problem as well as we code further
@danielhaag756
@danielhaag756 Жыл бұрын
Ya I am also facing same problem, I am also not able to understand the problem
@samit840
@samit840 Жыл бұрын
@@danielhaag756 tell me one thing bro, i watched the video till 4-5 mins, and then i noticed that we would be doing it same way as we did in KOKO bananas, so is it fine that i watched the video till this???
@Vivekkumar-zc7mz
@Vivekkumar-zc7mz 9 ай бұрын
how much time you takes to reach at that level and what are the hacks u have learnt that helped u ??
@pranavJha93
@pranavJha93 8 ай бұрын
there is one tip i will give u see there two types of cases either you are able to solve a problem either you are not when when you are not able to solve a problem first make notes of it after watching tutorial of it and then do the same question by yourself after 7 days if u are able to do it in by your own without copying that means u actually grabbed the concept of it and it will also boost your confidence @@Vivekkumar-zc7mz
@ranjeet_sohanpal
@ranjeet_sohanpal 8 ай бұрын
@@Vivekkumar-zc7mz there are no hacks
@morty6456
@morty6456 Жыл бұрын
My strategy of following the striver sheet is that at first I try to solve the question myself and if I am unable to then I come to videos for understanding, After reading this question on leetcode, I was clueless even about the question itself 1:35 mins into video and I have solved it on my own. Is this magic or something? 😅 Thank you bhaiyaaaaaaaaaaa❤
@syedfazil2998
@syedfazil2998 Жыл бұрын
exact same thing but at 2:15
@pulkitjain5159
@pulkitjain5159 Жыл бұрын
currently 259 questions kar liye hai apki sheet ke , dekhte hai aur kitne kar pata hu , quality of questions awesome hai bhaiya , monotnic stacks m aur sliding windows m toh kya tagde question daal rakhe hai every question improves thinking in other direction. Ab bas graphs , greedy , trees , heaps aur strings bach raha hai usme bhi umeed hai bahut shandar questions honge. karta hu bhiaya dekhte hai kab tak khatam hogi , jab binary search kar raha tha tab i really wanted ki yeh videos ajaye but jo khud grind kiya na woh alag hi satisfaction tha. kabhi bhulayega nahi yeh questions , jitna video dekh ke bhool jaate hai. ek video ke peeche itni mehnat hoti hai itni research hoti hai , samajh agya. Waise app thoda rest bhi karliya karo aur jyada soya karo , peace of mind jyada important hai. Thank you for free knowledge 😊.
@krishnaramtripathi958
@krishnaramtripathi958 Жыл бұрын
nunnu touching comment
@pulkitjain5159
@pulkitjain5159 Жыл бұрын
@@krishnaramtripathi958 thanks bro BTW completed the sheet :).
@GauravKashyap-ei6mb
@GauravKashyap-ei6mb Жыл бұрын
​@@pulkitjain5159Bro Is it possible to connect with you? I have few doubts regarding dsa.
@vaibhavvm4147
@vaibhavvm4147 11 ай бұрын
@@pulkitjain5159 bro from where did u learn dsa
@KrishnaKumar-b4m9p
@KrishnaKumar-b4m9p Күн бұрын
@@pulkitjain5159 hi are u placed now??
@raZer.7_
@raZer.7_ 6 ай бұрын
Little by little feeling confident in solving DSA problems. Thank you man!!
@thegreekgoat98
@thegreekgoat98 Жыл бұрын
Saw the first 9 minutes of the video and able to code it by myself. Such is the clarity in his explanations. Thanks Striver.
@thisismr900
@thisismr900 Жыл бұрын
Thank u striver sir. Really an inspiration to me. U know what ,I feel NOW very confident in solving the questions. Bas logic samajh aa jaye to code to bas 5 min lagta hai. 2 days complete , now at 13th video of this playlist .
@momentcoder
@momentcoder Күн бұрын
Finally I completed the first medium problem by myself, without understanding the approach first from the video. 😀 Thanks for the guidance Raj bhaiya (Striver). 🙏
@BroodWar4Ever
@BroodWar4Ever 5 ай бұрын
I could not wrap my head around this problem until I saw your video, thank you!
@indroneelgoswami5654
@indroneelgoswami5654 3 ай бұрын
Only 5 mins watching and solved the Question!! Striver you beauty!!!!!!!!!!!!!!!!!!!!!!!
@SumitSingh-dc8pm
@SumitSingh-dc8pm 11 ай бұрын
Solved this today, 13 Dec 2023. Thank you man for making the problem a cakewalk.
@Nexus-bg3
@Nexus-bg3 7 ай бұрын
I wasn't able to solve mid level binary search problems. Now i can easily. I can't thank you enough
@JoyBoy_013
@JoyBoy_013 9 ай бұрын
It becomes easier to understand when Striver starts explaining
@reshmah1497
@reshmah1497 27 күн бұрын
Coded myself in 3 minutes. Thanks for great teaching.
@himangshusarma6384
@himangshusarma6384 Жыл бұрын
UNDERSTOOD ! Instead, I solved it by my own before watching the video... Thanks to you
@akshaygupta811
@akshaygupta811 Жыл бұрын
A small optimization: defining long longs and checking for the condition m*k>n is not necessary, once the binary search finishes, if m*k>n is true, then our Low pointer would point at n. Hence at last we can just simple write: if (low==n) return -1; else return low;
@6mahine_mein_google
@6mahine_mein_google Жыл бұрын
It really isn't an optimization per se. Because if we calculate it beforehand we dont need to apply binary search at all , if(m*k>n) is true then it will straight away throw -1 whereas in your approach it would still take O(N*logN) , because it will go into binary search loop nevertheless.
@dank7044
@dank7044 Жыл бұрын
how is it an optimization lol? it ulta increases the Tc.
@23cash86
@23cash86 Жыл бұрын
at 3:53 I understood it is binary search, implemented on my own using binary search + sliding window ....Made some modification to sliding window as window cannot be overlapped to count consecutive k elements, got overflow error while checking n< m*k ... typecasted to n< (long) m*k ,finally passed all test cases after 40min..... Edit: after submiting i watched video and realised its easier to implement possible function , same complexity as sliding window but i could probably code you idea faster and it is simpler XD. Grateful for free knowledge from you.
@aksharshah
@aksharshah 5 ай бұрын
Striver always on fire🔥❤ excellently explained 😊
@div9210
@div9210 5 ай бұрын
I forgot to write noOfB += (cnt / k); again outside the loop in possible function, and it took me so much time to solve it myself, but i was able to do it after some time. So much thanks!
@johndurai2226
@johndurai2226 Жыл бұрын
Thank you striver bro I am from the south india (Tamilnadu). You are the consistency person keep it up and post videos as well. These are helpfull for us. Please made videos like this consistency.Thank you
@priyanshunautiyal1662
@priyanshunautiyal1662 7 ай бұрын
you are a great striver love the way you approach problems ....... Clearly Understood
@adamyagaur9638
@adamyagaur9638 3 ай бұрын
Minor optimization in TC: Instead of taking the complete range from lowest element to the highest element, just take unique sorted elements from the array for the binary search. This will reduce the log(max-min) complexity part to log(N), however the space complexity will change to O(N) from O(1)
@Manishgupta200
@Manishgupta200 Жыл бұрын
isPossible() function and taking long long as val = m*k to avoid overflow error is too tricky and helpful to understand the question clearly
@krishnavamsiyerrapatruni5385
@krishnavamsiyerrapatruni5385 Жыл бұрын
Understood everything clearly and was able to code it myself. Thanks a lot Striver :)
@danish15
@danish15 5 ай бұрын
Thanks it wasn't an easy problem statement to understand but after your explanation I was able to solve it on my own. 🙏
@joeljacob4685
@joeljacob4685 Жыл бұрын
Wow !! I am able to understand the intuition behind these problems. Excellent Problem and awesome explanation.
@ArijitsClasses
@ArijitsClasses 10 ай бұрын
Good evening sir, this is Arijit from Kolkata. Your videos are super amazing and helpful, getting confidence in attempting leetcode problems...could even solve few of them. Sir the purpose of this comment is, as you said in one of the TEDX videos that in your college days you used to earn through blogging...may you please suggest me some tips, how can I earn through blogging, and recommend some blogging websites from where I can earn too....
@VinuthaTJ-u7o
@VinuthaTJ-u7o 5 ай бұрын
Best! Best! Bestest explanation ever!!
@faizanahmed9304
@faizanahmed9304 Жыл бұрын
Thank you Striver bhaiya!
@MJBZG
@MJBZG 4 ай бұрын
could code it by myself before reading the explanation, thanks!
@tanujaSangwan
@tanujaSangwan 2 ай бұрын
Completed the code without watching the video all by myself
@nukuldevsinghkhichi
@nukuldevsinghkhichi 28 күн бұрын
Greato🎉
@sauravchandra10
@sauravchandra10 Жыл бұрын
Was able to code this on my own, thanks and understood clearly!
@kaushiksen2190
@kaushiksen2190 Жыл бұрын
Thank you so much Dada, i was able to solve it on my own by taking help from the previous question intuition
@cinime
@cinime Жыл бұрын
Understood! Amazing explanation as always, thank you very very much for your continuous effort!!
@alessandrocamilleri1239
@alessandrocamilleri1239 Жыл бұрын
Great explanation. TC should include an additional O(n) to find range.
@elizabethr5161
@elizabethr5161 Жыл бұрын
yes correct
@akhileshagarwal5913
@akhileshagarwal5913 8 ай бұрын
What a Great Approach Man
@Avi-rc5ff
@Avi-rc5ff 5 ай бұрын
The explanation is so good
@udatyadeb101
@udatyadeb101 10 ай бұрын
thanks to you was able to do the problem on my own.
@BiswajitDas-lk7pp
@BiswajitDas-lk7pp 10 ай бұрын
Better than Paid Courses
@divya1005
@divya1005 5 ай бұрын
Thank you so much for the super clear explanation 🙂
@stephan24297
@stephan24297 5 ай бұрын
thanks for the explanation definitely helped me to understand the problem!
@shamanthhegde2820
@shamanthhegde2820 8 ай бұрын
while solving the same problem in leetcode, i encountered a condition where the code might fail. for instance when there are enough flowers but they are not adjacent to make enough bouquets. so during that case our low pointer will go beyond the size of the array. In order to counter that , we have to check the position of low...if the position of low > maxDay then we have to return -1 as we were not able to satisfy number of bouquets.
@ShravanKumar-wg9pv
@ShravanKumar-wg9pv 3 ай бұрын
understood very well sir
@statusupdate7007
@statusupdate7007 4 ай бұрын
Understand bro great teaching 👍
@abhishekkumargupta117
@abhishekkumargupta117 Жыл бұрын
wow! very well explained.
@AtulKumar-c4x7l
@AtulKumar-c4x7l Жыл бұрын
understood Thank you striver for such an amazing explanation...
@dipingrover1970
@dipingrover1970 5 ай бұрын
amazing explantion i was able to do it on my own. 😊
@adityaroychowdhury3709
@adityaroychowdhury3709 Жыл бұрын
understood. thank you very much for this series.
@pushankarmakar1783
@pushankarmakar1783 9 ай бұрын
why cant we do it in a way where the possible() function would return the bouquets we are able to form and then we deal with what to do in the binary search?
@amanasrani6405
@amanasrani6405 4 ай бұрын
Amazing Explanation 🙌❤
@Bigg_boss_trolls
@Bigg_boss_trolls 7 күн бұрын
it becomes easy when striver explains💀
@dayashankarlakhotia4943
@dayashankarlakhotia4943 Жыл бұрын
Good problem very well explained. Thanks.
@RaunitJaiswal-s9v
@RaunitJaiswal-s9v 2 ай бұрын
Done
@AK-nj1je
@AK-nj1je 8 ай бұрын
Done and Dusted !!!
@ritikkurta3363
@ritikkurta3363 Жыл бұрын
happy birthday bhai bhai
@cenacr007
@cenacr007 Жыл бұрын
the opposite polarity is very useful.
@prakhargarg4166
@prakhargarg4166 5 ай бұрын
Best intuition
@AnmolGupta-oj4lm
@AnmolGupta-oj4lm Жыл бұрын
Understood Very Well!
@culeforever5408
@culeforever5408 Жыл бұрын
understood 😇
@ishangujarathi10
@ishangujarathi10 Жыл бұрын
Understood completely, tysmm striverrrrrr
@deepakff7498
@deepakff7498 Ай бұрын
17:33 AND 24:20
@googleit2490
@googleit2490 Жыл бұрын
Understood, coded it on my own, thanks!!
@vedantrajanikantlatthe735
@vedantrajanikantlatthe735 5 ай бұрын
you are great sir
@manavsingh5919
@manavsingh5919 Жыл бұрын
thank you striver understood everything
@vaibhav5269
@vaibhav5269 10 ай бұрын
Hi striver At 20:20 , you directly ignored less than 10 days, but what if bloom days array was something like this [7,7,7,7,13,11,12,7,7,7] In this case 2 bouquets are possible for minimum of 7 days, but we have ignored 7 days in binary search.
@vivekprasannan9258
@vivekprasannan9258 10 ай бұрын
Bro, in your case 10 days is a possible ans, so according to binary search the ans will store 10 and try to search for a min day than 10 (right half is ignored). Hope it helps
@srija0608
@srija0608 27 күн бұрын
Understood 👍
@Ina2003-q4s
@Ina2003-q4s Жыл бұрын
Love from Mysore ❤
@oyeesharme
@oyeesharme 3 ай бұрын
understood bhaiya
@AyushGupta-kb9iv
@AyushGupta-kb9iv Жыл бұрын
class Solution { public: bool f(vector &a, int m, int k, int midDay) { int cnt=0, noOfBookey=0; for(auto x: a) { if(midDay>=x) cnt++; else { noOfBookey += (cnt/k); cnt=0; } } noOfBookey += (cnt/k); return noOfBookey >=m; } int minDays(vector& a, int m, int k) { if(1ll*m*k > a.size()) return -1; int lo=1e9, hi=-1e9, mid, ans=-1; for(auto x: a) { lo=min(lo, x); hi=max(hi, x); } while(lo>1; if(f(a, m, k, mid)) { ans=mid; hi=mid-1; } else lo=mid+1; } return ans; } };
@CodeMode9313
@CodeMode9313 Жыл бұрын
Habibi tussi mast bideo banate ho
4 ай бұрын
Thank you sir
@AbhishekKumar-nz9dn
@AbhishekKumar-nz9dn Жыл бұрын
UNDERSTOOD 🥰
@smoothgaming7822
@smoothgaming7822 Жыл бұрын
Understood sir!
@DeadPoolx1712
@DeadPoolx1712 3 ай бұрын
UNDERSTOOD;
@Learnprogramming-q7f
@Learnprogramming-q7f 9 ай бұрын
Thank you bhaiya
@kaushiksen2190
@kaushiksen2190 Жыл бұрын
Keep going thanks alot
@bharatmundra9568
@bharatmundra9568 Жыл бұрын
amazing sir
@YourCodeVerse
@YourCodeVerse 11 ай бұрын
Understood✅🔥🔥
@SYCOA12CHAITANYAASOLE
@SYCOA12CHAITANYAASOLE 5 ай бұрын
Understood !! 😎😎
@srikanthkumar6842
@srikanthkumar6842 Жыл бұрын
Thank you
@Anony.musk01
@Anony.musk01 Жыл бұрын
Understood!
@TON-108
@TON-108 Жыл бұрын
Understood!
@md.imrankhan6912
@md.imrankhan6912 Жыл бұрын
Legendary boss
@stormragemc4375
@stormragemc4375 5 ай бұрын
if i may once you've found out 12 (mid) is possible, why do you still need to eliminate the ranges and continue looking when it's safe to assume that since you've ordered the list the first number you found possible would be the smallest possible and u got ur answer already?
@mohammedansil2302
@mohammedansil2302 5 ай бұрын
he is a fire❤‍🔥❤‍🔥❤‍🔥❤‍🔥❤‍🔥
@lethalgaming7087
@lethalgaming7087 Жыл бұрын
Java Code : public class Solution { public static int roseGarden(int[] arr, int k, int m) { int n=arr.length,low=1,high=0,ans=0; if(k*m>n) return -1; for(int i:arr) if(i>high) high=i; while(low>>1; if(isPossible(arr,mid,k,m)) { ans=mid; high=mid-1; } else low=mid+1; } return ans; } private static boolean isPossible(int[] arr, int mid, int k, int m) { int adjl=0,bc=0; for(int i:arr) { if(mid>=i) adjl++; else adjl=0; if(adjl==k) { bc++; adjl=0; } if(bc==m) return true; } return false; } }
@senseiAree
@senseiAree Жыл бұрын
Understood ❤
@sahilsinghtomar
@sahilsinghtomar Жыл бұрын
nice one
@sakshinaruka3440
@sakshinaruka3440 Жыл бұрын
Understood :) Thank you so much
@per.seus._
@per.seus._ Жыл бұрын
UNDERSTOOD
@arujain1690
@arujain1690 Жыл бұрын
Can someone please help me understand what is polarity concept striver was talking about?
@Bharat_Rider
@Bharat_Rider Жыл бұрын
Initially low was on the not possible side and high on the possible side. This is polarity. Now as the binary search ends polarity changes i.e. low will be on possible and high on not possible.
@darkpheonix6592
@darkpheonix6592 5 ай бұрын
simply binary search is converting o(n2) solution to o(nlogn) solution
@rohithdarlanka
@rohithdarlanka Жыл бұрын
understood
@raghavkansal3765
@raghavkansal3765 Жыл бұрын
"understood"
@ShamsiaJim
@ShamsiaJim 9 күн бұрын
Can you kindly upload the String Videos on Striver's A2Z DSA Course? (!)
@RaviKumar-sn6tu
@RaviKumar-sn6tu 7 ай бұрын
understood!!
@AnandSharma-ei1fv
@AnandSharma-ei1fv 5 ай бұрын
understoood
@humanity7880
@humanity7880 Жыл бұрын
understood!
@soumiyamuthuraj3516
@soumiyamuthuraj3516 5 ай бұрын
Awesome
BS-14. Find the Smallest Divisor Given a Threshold | Binary Search
16:00
Maximum Number of Points with Cost - Leetcode 1937 - Python
15:15
А я думаю что за звук такой знакомый? 😂😂😂
00:15
Денис Кукояка
Рет қаралды 4,6 МЛН
Как Я Брата ОБМАНУЛ (смешное видео, прикол, юмор, поржать)
00:59
Кто круче, как думаешь?
00:44
МЯТНАЯ ФАНТА
Рет қаралды 6 МЛН
BS-17. Aggressive Cows | Binary Search Hard
26:44
take U forward
Рет қаралды 176 М.
BS-16. Kth Missing Positive Number | Maths + Binary Search
22:52
take U forward
Рет қаралды 159 М.
Should you grind LeetCode? feat. NeetCode | 051
56:22
Backend Banter
Рет қаралды 58 М.
The LeetCode Fallacy
6:08
NeetCode
Рет қаралды 576 М.
BS-12. Koko Eating Bananas
21:04
take U forward
Рет қаралды 187 М.
How to Solve ANY LeetCode Problem (Step-by-Step)
12:37
Codebagel
Рет қаралды 303 М.
А я думаю что за звук такой знакомый? 😂😂😂
00:15
Денис Кукояка
Рет қаралды 4,6 МЛН