In DSA sure is this best For development check chai aur code once
@vm1662 Жыл бұрын
Great tip! Whenever there is a possible range of answers then we can apply binary search.. Thanks a lot Striver!
@LokeshPandey-m1m Жыл бұрын
never thought we could even solve this by binary search mind-blowing
@sauravchandra10 Жыл бұрын
I remember doing this question earlier but the way you taught I am confident I can now easily solve problems like these in interviews with a clear and intuitive explanation. Understood, thanks!
@keshav95416 ай бұрын
same
@pradyumnmulegaon38511 ай бұрын
for those who are solving in leetcode the TotalH should be long long and also the CalculatetotalHours should also be long long type otherwise it will throw an error ..... hope it is helpful
@socify441011 ай бұрын
it was throwing run time error earlier. i thought i must be missing some edge case . after this change it got submitted. thanks to you buddy
@tanishagarwal599211 ай бұрын
Why to calculate total hours just check if it any instance the req time crosses h... Return false
@ArunsinghParihar-j3j9 ай бұрын
When I was submitting my code, I encountered the same problem, Thanks buddy.
@tusharkhatri29218 ай бұрын
Bro on LeetCode not working after 121 test cases.
@ranjeet_sohanpal8 ай бұрын
@@tusharkhatri2921 you can make the condition in the calculation of hour .When the time taken exceeds h, you immediately return that val and prevent the overflow
@mathguy198 Жыл бұрын
Thanks Striver, always struggled to understand the reason behind the answer being always the low value, now it's clear as crystal, all thanks to you❤❤
@--Blood--Prince-- Жыл бұрын
I see Koko is on a high carb diet😀😅
@prernagupta7729 Жыл бұрын
😂
@SreeCharan-dx7oc8 ай бұрын
🤣🤣
@dumpster-jackson5 ай бұрын
Gay
@omkarshendge54384 ай бұрын
lmao but tbh koko is a monkey i think thats why he is eating bananas!
@kumarvansh0074 ай бұрын
@@dumpster-jackson wtf
@visheshagrawal8676 Жыл бұрын
I have earlier solved the question but intuition of yours is truly amazing... Great Content 🔥🔥
@thenikhildaiya. Жыл бұрын
I just saw the question explanation and did the brute force and binary search approach all by myself just because of your previous videos explanation. Thank you so much for this wonderful and guided course.
@kumarshivam3661 Жыл бұрын
Bro please post the solution of code
@thenikhildaiya. Жыл бұрын
@@kumarshivam3661 ** Brute Force : class Solution { public: int minEatingSpeed(vector& piles, int h) { int maxHours = -1 , k = 0 ; for(int i = 0 ; i < piles.size() ; i++) if(piles[i] > maxHours) maxHours = piles[i] ; for(int i = 1 ; i
@nostalgiccringeallhailchel3881 Жыл бұрын
how far have you progressed in 3 weeks bro pls update
@thenikhildaiya. Жыл бұрын
@@nostalgiccringeallhailchel3881 I did aggressive cows at last. Not good progress at all because of college exams🥲 Just revising old linked list questions I did in past.
@nostalgiccringeallhailchel3881 Жыл бұрын
@@thenikhildaiya. Which topic is aggressive cows in?
@akashdutta162011 ай бұрын
this was asked in an interview I came up with this solution without solving this before.. :)
@lshuarckymaАй бұрын
STRIVERS TIP always find out the range ie low and high for applying the binary search bcz it could even work for larger ranges but will be efficient for the lowest high or the highest low. TIP 2 the pointers high and low always end up at opposite polarity of the condition ie for ex here POINTER low from being the speed in which eating in time isnt possible end up to possible minimum so without using the ANS directly use the POINTERS
@CrazyHunk149 ай бұрын
thanks to your intuition I could do this question on my own using the same approach that you explained in this video without any help! kudos
@SuvradipDasPhotographyOfficial Жыл бұрын
The wait is finally over.... Thanks a ton striver❤
@impalash_ag4 ай бұрын
Hi Raj, Both the BF and Optimal solutions will have an additional TC of O(n) to find the maximum element from the array.
@ArdentMusicLover2 күн бұрын
Thank you, Striver. Loved the intuition on "binary search on answers" and on how to pick low or high as final answer. One quick suggestion: The python code provided in the solution is INCORRECT because ceil computation needs to be float.
@ritiksoni52557 ай бұрын
Thankyou you so much finally able to understand the approach and logics for solving DSA!!
@shashwatkumar69659 ай бұрын
Great video! Just wanted to add one thing, in the question's Constraints it's given that n
@sukhii02205 ай бұрын
just include the overflow condition in finding the hrs in the loop only if totalH >H break;
@Dipanshutripathi2407 Жыл бұрын
I have no doubts after watching ur videos.
@Bigg_boss_trolls11 күн бұрын
Thanks a lot Striver!
@Amanali-rl9hw Жыл бұрын
finally found when to return the low and when to return the value high
@knowthrvdo9 ай бұрын
logic is same as finding first occurance THANK YOU
@varun10179 ай бұрын
use long long to calculateTotalHours instead of int to avoid overflow
@ayushgoel01 Жыл бұрын
🔴Leetcode Solution:- class Solution { private: int maxi(vector arr){ int ans = INT_MIN; for(int i=0; i
@Manishgupta200 Жыл бұрын
Rather than using ceil we can use "sum = sum + (v[i] - 1)/ mid + 1;" It's more optimal
@shikharjoshi2998 Жыл бұрын
what's the logic behind the (v[i]-1) ??
@HemanthD-bf4he8 ай бұрын
Can you explain the logic?
@cinime Жыл бұрын
Understood! Wonderful explanation as always, thank you very very much for your effort!!
@visheshagrawal8676 Жыл бұрын
If anyone was getting runtime error of integer overflow do change the datatype of totalhours to double or long long
@AtulKumar-c4x7l Жыл бұрын
understood Thank you striver for such an amazing explanation..
@tejanshsachdeva487 Жыл бұрын
The typecasted leet-code code: #include #include #include class Solution { private: int maxEl(vector& piles) { int maxi = INT_MIN; for (int i = 0; i < piles.size(); i++) { maxi = max(maxi, piles[i]); } return maxi; } long long totEl(vector& piles, int mid) { long long totH = 0; int n = piles.size(); for (int i = 0; i < n; i++) { totH += (piles[i] + mid - 1) / mid; // Updated calculation } return totH; } public: int minEatingSpeed(vector& piles, int h) { int low = 1; long long high = maxEl(piles); int ans = INT_MAX; while (low
@Jus-chill Жыл бұрын
Understood Please do upload videos consistently 😊
@debanjanghosal6182 ай бұрын
I solved this problem but I cant get over 1 doubt? Why are we setting low to 1? Won't it be better if we set low as the minimum number of bananas among all the piles?
@rahulreddyambati90653 ай бұрын
A typical De-Shaw intern OA question
@aniketgupta8064 Жыл бұрын
hey striver, I feel that there is some problem with the leetcode question. for the testcase [805306368, 805306368, 805306368] and h = 1000000000, the expected answer is k=3 when we use an ans variable to store the desired value of mid, the code gives output = 1 which is incorrect, however, when we simply return the low, the testcase passes. I am not able to understand what is happening here. If this is a case of an overflow, I have already substitued long long. Pls help.
@thegame587 Жыл бұрын
bool check(vector& piles,int h,int k){ long long ans=0; for(int i=0;ih)return false; } //cout
@aniketgupta8064 Жыл бұрын
@@thegame587 Thanks a lot buddy for replying, it's working now. I had figured the overflow problem :)
@jayant-baid Жыл бұрын
@@aniketgupta8064 you can also make the func dataype, totalH datatype to long, this can also works
@aniketgupta8064 Жыл бұрын
@@jayant-baid thanks 👍
@MYMIND252 Жыл бұрын
@@jayant-baid thank you bro i stuck in this problem for more than hour and you save me from it 😊😊
@joeljacob4685 Жыл бұрын
Thanks so much!! I was able to solve it without watching the video !!
@DikshaNarang-q9l Жыл бұрын
while finding maximum element in an unsorted array it takes O(n) time so ultimately the time complexity of this question is O(n).
@prthmsh293010 ай бұрын
O(n*log(max) >>> O(n) :)
@rushidesai28366 ай бұрын
public int findHours(int[] arr, int bananaCount) { int totalHrs = 0; for (int i = 0; i < arr.length; i++) { totalHrs += Math.ceil((double) arr[i] / bananaCount); } return totalHrs; } Cast to double, because ceil here needs floating-point number.
@hareshnayak73028 ай бұрын
Understood, Thanks striver for this amazing video.
@Shikaslad-s5f6 ай бұрын
To reduce runtime one can use instead of ceil ans += (piles[i]+k-1)/k;
@Surya1prakash Жыл бұрын
Really amazing explanation 👏
@manavsingh5919 Жыл бұрын
Thank you striver....Understood everything🙂...keep up the good work
@padmavatishah99228 ай бұрын
fr?
@abdussalam-48364 ай бұрын
why i feel like i am watching these videos again
@tanujaSangwan2 ай бұрын
Solved this without watching the video myself
@AyushSharma-sd1ny Жыл бұрын
Great explanation Striver
@abhaythakur2597 Жыл бұрын
very helpful explaination
@RaviRavi-kt9gt Жыл бұрын
You are just incredible ❤️🎉🎉
@aritramallik8173 Жыл бұрын
Dada tumi best❤❤❤
@yashendrabadal47765 ай бұрын
Koko for real is gonna shit the whole next day ! AWESOME VID STRIVER
@AnmolGupta-oj4lm Жыл бұрын
Understood Very Well!
@arvindokram29063 ай бұрын
Got asked this question today!
@jhanavikumari2744 ай бұрын
it is actually similar to finding the smallest divisor than threshold question literally
@Thescienceworld652 Жыл бұрын
i was doing this wrong for three hours and what i was doing wrong was only not applying double🙂
@pradipkumarmukhiАй бұрын
Understood Man You damn it!!!
@sateeshkumar16349 ай бұрын
Hey striver, i am getting 1 test case wrong in this question, don't know why i still tried with your own code , but it is not working, nearly 3 problems have been in this way, any one please respond....
@aaranyaksantra99335 ай бұрын
nice explaination
@harshitjaiswal9439 Жыл бұрын
Understood!
@ShivamMaurya-fq6ws Жыл бұрын
@striver thanks for explanation
@A_Myth9638 ай бұрын
For people doing on leetcode and getting error after testcase 120 ...just use long long hrtaken and also return long long.. Here's the code if someone needs it class Solution { public: long long hrtaken(vector pi, int h) { long long hr = 0; for (auto i : pi) { hr += ceil((double)i/(double)h); } return hr; } int minEatingSpeed(vector& piles, int h) { int maxt = -1; int m = -1; for (auto i : piles) m = max(m, i); int low = 1, high = m; while (low
@srinivasareddychalla-i2o Жыл бұрын
Could you also please explain.Find K close elements with binary search.I've seen in some of the binary search approaches.Few of the solutions are with right=mid or left=mid.
@culeforever5408 Жыл бұрын
understood 😇
@happylearning647611 ай бұрын
Should we not consider the + O(n) time to find the max element in the time complexity? Though i does not add to the over all complexity since we take the high value, still asking
@umangkumar20059 ай бұрын
little explanation solve the whole question #include using namespace std; bool fun(vector & v,int h ,int &ans, int mid){ int sum=0; for(int i=0;ih){ return true; } } ans=mid; return false; } int minimumRateToEatBananas(vector v, int h) { int ma=INT_MIN; for(int i=0;i
@AdityaYadav-qf9qc Жыл бұрын
Best explaination😍
@pritivarse2129 Жыл бұрын
Sir plz make videos on linked list and string part from A to Z dsa sheet
@_CodeLifeChronicles_2 ай бұрын
i got a q same like this in uber where hours were same but here it is a car and we need to find min kwperh so that the cars can get charged . but right now i am in my third year and gave uber in the beginning of the year and i didnt have any idea abt this. thank go i am on a strict plan of action now hope i will be able to solve q next time in OA
@ayushjaiswal7298 Жыл бұрын
Best explanation 🔥
@tanishkarawat5266 Жыл бұрын
One doubt: what if h = 5 and piles = [30,11,23,4,20]here if we take k greater than 30 then also we'll get the answer. Then how can we apply that brute force where we are taking range of k to be [1, greatest_element] in that array?
@akshaykeswani3601 Жыл бұрын
Really Amazing👏👏👏
@akashgite9054 ай бұрын
koko needs to stop eating those bananas
@dayashankarlakhotia4943 Жыл бұрын
Good explanation understood
@NazeerBashaShaik7 ай бұрын
Understood, thank you.
@AnilKumar-mg8sj2 ай бұрын
Thanks!
@hitmanop40785 ай бұрын
Someone please give a advice like how can u build a logic, how to revice sometimes I just go all blank even in some easy question what should I do ??.
@neelnsoni1313 Жыл бұрын
Thank You
@chethanprabhu44754 ай бұрын
Should we not add the O(n) to time complexity to find the max element in the array
@debhagaming Жыл бұрын
Nice explanation ❤
@yashraj589819 күн бұрын
to clear all the test cases . class Solution { public: int findmaxelement(vector& piles){ int maximum = INT_MIN; int n = piles.size(); for (int i=0; i
@gnanaphanideep639819 күн бұрын
Understood😁
@oyeesharme3 ай бұрын
understood bhaiya
@YourCodeVerse11 ай бұрын
Understood✅🔥🔥
@frostyfreezemovies Жыл бұрын
I am using javascript😇
@Learnprogramming-q7f9 ай бұрын
Thank you bhaiya
@debanjan10 Жыл бұрын
@DeadPoolx17123 ай бұрын
UNDERSTOOD;
@Yahsaswi Жыл бұрын
was waiting for this
@Aryan-j7i2b22 күн бұрын
understood!!!
@ravisingla9032 Жыл бұрын
Was Waiting for the same
@VishalGupta-xw2rp Жыл бұрын
16:50 Low opposite polarity
@sumitdon20044 ай бұрын
striver is best
@harshilpatel32059 ай бұрын
Understood sir 🫡🤍
@lakshyabhati22629 ай бұрын
but if the array is sorted then we don't need to find max of array .. its just the last element of the array .. i guess
@per.seus._ Жыл бұрын
understood
@farzadkhan3813 Жыл бұрын
Understood!!
@amarsharma858210 ай бұрын
**IMPORTANT** For CEIL VALUE you can use (a+b-1)/b this works well. example: arr = 2 3 6 8 mid = some value X then ceil value = (arr[i] + mid - 1)/mid
@senseiAree Жыл бұрын
Understood ❤
@girikgarg8 Жыл бұрын
Done
@shashankvashishtha44545 ай бұрын
understand
@AbhishekBhattacharjee-j2m Жыл бұрын
UNDERSTOOD
@amaankhan9845 Жыл бұрын
Following this series. Really helpfull 💪💪
@ziggywiggys5 ай бұрын
Why does it not work if I take the minimum eating speed as the minimum of the array ?
@abhishek_dagar Жыл бұрын
Leetcode solution all test cases passed : class Solution { public: int findmaximum(vector &piles){ int n = piles.size(); int maxi = INT_MIN; for(int i =0; i