CANDY | 2 Approaches | O(1) Space | O(N) Space | AMAZON | Leetcode - 135

  Рет қаралды 7,009

codestorywithMIK

codestorywithMIK

9 ай бұрын

This is the 18th Video on our Greedy Playlist.
In this video we will try to solve a very good Greedy Problem - CANDY (Leetcode-135).
Trust me, this will no longer be a Hard Problem.
I will explain the intuition so easily that you will never forget and start seeing this as cakewalk EASYYY.
We will do live coding after explanation and see if we are able to pass all the test cases.
Problem Name : CANDY
Company Tags : AMAZON
My solutions on Github : github.com/MAZHARMIK/Intervie...
Leetcode Link : leetcode.com/problems/candy/
My DP Concepts Playlist : • Roadmap for DP | How t...
My Graph Concepts Playlist : • Graph Concepts & Qns -...
My GitHub Repo for interview preparation : github.com/MAZHARMIK/Intervie...
Subscribe to my channel : / @codestorywithmik
Instagram : / codestorywithmik
Facebook : / 100090524295846
Twitter : / cswithmik
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge#leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook

Пікірлер: 83
@sachinmohanty4577
@sachinmohanty4577 9 ай бұрын
Approach 2 is op❤
@codestorywithMIK
@codestorywithMIK 9 ай бұрын
Thank you so much ❤️🙏
@siddharth.chandani
@siddharth.chandani 2 ай бұрын
Whenever I searched for a question & found your video then I feel so happy that this man will definitely explained me solution... Thanks a lot for your brilliant explanation as always😄
@wearevacationuncoverers
@wearevacationuncoverers 9 ай бұрын
Man you are just on another level. I have literally never seen such kind of in-depth explanation in any channel yet. And that too free
@sarveshjoshi6913
@sarveshjoshi6913 Күн бұрын
u are really talented but very underrated bhai❣
@AlishaKhan-ww3io
@AlishaKhan-ww3io 9 ай бұрын
One of the best explanations of 2nd approach I found since morning. Most of the channels have not discussed approach-2 . You nailed it.
@Thriftinghai
@Thriftinghai 9 ай бұрын
No one can beat the explanation of this channel.
@aliksarkar2935
@aliksarkar2935 3 ай бұрын
awesome dude :) great approach
@itsaayush7357
@itsaayush7357 5 ай бұрын
M dam sure no one can beat mik in explaination of code. He makes u understand like u r a small kid learning from your elders. Thank you bro, for these clear content and your efforts.
@codestorywithMIK
@codestorywithMIK 5 ай бұрын
You made my day. Thank you so much ❤️❤️🙏😇
@TheBusaSinger
@TheBusaSinger 9 ай бұрын
Best Explanation! 👍🏻
@mailatkaushal
@mailatkaushal 8 ай бұрын
thanks for the o(1) solution bhaiya... i could'nt find it anywhere else...
@shabananoor9423
@shabananoor9423 9 ай бұрын
2nd explanation is really good . Thanks 👍
@souravjoshi2293
@souravjoshi2293 9 ай бұрын
I am always relieved now that whenever there is a problem I am stuck in, there will be MIK who will make it easy for me.
@trailsnail
@trailsnail 9 ай бұрын
2nd approach reminds me of counting valleys question from hackerrank. But i would never have thought to apply it in this question
@codestorywithMIK
@codestorywithMIK 9 ай бұрын
Absolutely. It reminded me about the valley qn. I also remember that the Valley qn was asked in OA of swiggy once some months back.
@pokeindia5361
@pokeindia5361 17 күн бұрын
​@@codestorywithMIKcan u give link of that valley Question??
@avnish-wf8rv
@avnish-wf8rv 9 ай бұрын
I watched this video till R2L logic and paused started to code I was able do I myself. Thanks again.😍
@codestorywithMIK
@codestorywithMIK 9 ай бұрын
That’s absolutely what I want. Just understand the logic and intuition and then try the code on your own. Thank you for sharing ❤️🙏😇
@tutuimam3381
@tutuimam3381 9 ай бұрын
Thanks a lot
@obulpathi2729
@obulpathi2729 6 ай бұрын
Thank you for sharing the 2nd approach, the leet code's official solution made it very complicated to understand, but you made it very simple.
@codestorywithMIK
@codestorywithMIK 6 ай бұрын
Glad it helped! 🙏❤️😇
@mahinhossen4251
@mahinhossen4251 5 ай бұрын
only video I found clearly explained 0(1) solution. Thank you so much. those dry runs were so helpful
@codestorywithMIK
@codestorywithMIK 5 ай бұрын
Glad it helped! 😇🙏
@surajsidar2294
@surajsidar2294 3 ай бұрын
The following is not passing the test cases (approach 2) What can be the reason? class Solution { public int candy(int[] ratings) { int n= ratings.length; int i=1; int candy =0; while(iratings[i-1]) { peak++; i++; candy+=peak; if(i==n) return candy; } //dip int dip=0; while(i
@yikes3807
@yikes3807 9 ай бұрын
Thank You Sir keep uploading the first approach was like trapping rain water
@codestorywithMIK
@codestorywithMIK 9 ай бұрын
Indeed. Thank you 😇🙏❤️
@aadil4236
@aadil4236 9 ай бұрын
Bhai kya intuition tha. Mene ye solve karliya tha, lekin vo intuition ni aa raha tha. Right lag raha tha muje lekin 100% intuition ni aa raha tha ke kyu ye kaam karna chaahiye. Kya samjaya he bhai. Aapki explain karne ki style bohot achhi he!!
@codestorywithMIK
@codestorywithMIK 9 ай бұрын
Thank you 🙏❤️😇
@kashifrahman
@kashifrahman 9 ай бұрын
With your solution the hard question also become easy
@codestorywithMIK
@codestorywithMIK 9 ай бұрын
Thank you 😇❤️
@balreddya6604
@balreddya6604 5 ай бұрын
Shandhar Explanation👌👌👌👌
@codestorywithMIK
@codestorywithMIK 5 ай бұрын
Thanks a lot 😊
@Abhay14
@Abhay14 9 ай бұрын
bhaiya kl ki video me aap explain krna ki aap question ko approach kaise krte ho, because maine jbb minimum dekha to maine socha isme recursion hogga buy ye greedy se ho rha h, pls tell your mindset while solving a new problem
@herculean6748
@herculean6748 9 ай бұрын
what an explanation! excellent!
@codestorywithMIK
@codestorywithMIK 9 ай бұрын
Thank you so much 😊
@sauravchandra10
@sauravchandra10 9 ай бұрын
Bohot time dry run krne ke baad finally samaj aaya!
@codestorywithMIK
@codestorywithMIK 9 ай бұрын
So glad to hear that ❤️👌
@dayashankarlakhotia4943
@dayashankarlakhotia4943 9 ай бұрын
2nd approach is best your explanation style is excellent 👌 🎉❤
@codestorywithMIK
@codestorywithMIK 9 ай бұрын
Thanks a lot 😊 ❤️
@sanjaykatta6499
@sanjaykatta6499 8 ай бұрын
Bro, on an average what is the amount of time you spend before arriving on a correct solution for a problem. Because sometimes it takes hour and more for me and still end up seeing your video for solution.
@motivationkiaag1601
@motivationkiaag1601 9 ай бұрын
Please make a solution video on Expression add operator leetcode question, No one on KZbin explained very well , i am waiting please
@sayandip8041
@sayandip8041 9 ай бұрын
Great explanation as always!!👌👏
@codestorywithMIK
@codestorywithMIK 9 ай бұрын
Thank you 🙏😇
@shoaibakhtar9194
@shoaibakhtar9194 5 ай бұрын
Great Explanation
@codestorywithMIK
@codestorywithMIK 5 ай бұрын
Glad it was helpful! 🙏
@ujjawaltyagi8540
@ujjawaltyagi8540 9 ай бұрын
the 2nd approach is not working anymore its giving error for test case : [1,3,4,5,2] output: 10 , expection code class Solution { public: int candy(vector& r) { int n = r.size(); int i=1; int candy = n; while(ir[i-1]) { peak++; candy+=peak; i++; if(i==n) return candy; } int dip = 0; while(i
@codestorywithMIK
@codestorywithMIK 9 ай бұрын
It seems to be working fine for me. All test cases are passing for me.
@ShrishDollin
@ShrishDollin 9 ай бұрын
second while loop se return mt kro, as told, after every cycle/mountain completed, extras substract krne hai. pehle hi return kiya isiliye 12 aa raha hai output instead of 11.
@anuppatankar4294
@anuppatankar4294 9 ай бұрын
Great Explanation 👌🏻
@codestorywithMIK
@codestorywithMIK 9 ай бұрын
Thank you 😊
@AmarjeetKumar-to9ub
@AmarjeetKumar-to9ub 9 ай бұрын
Thank You :)
@codestorywithMIK
@codestorywithMIK 9 ай бұрын
You're welcome! 🙏😇
@prashantvishwakarma6100
@prashantvishwakarma6100 9 ай бұрын
Tagdaa Sir ji.....
@codestorywithMIK
@codestorywithMIK 9 ай бұрын
Thank you 😇❤️
@SanjeevKumar-xv5lw
@SanjeevKumar-xv5lw 16 күн бұрын
is it normal if I am not getting full intuition? I have solved around 6-7 greedy problems
@oqant0424
@oqant0424 9 ай бұрын
Well explained bhaiya
@codestorywithMIK
@codestorywithMIK 9 ай бұрын
Thank you 🙏❤️
@codeandtalk6
@codeandtalk6 9 ай бұрын
❤❤
@umeshbisht1054
@umeshbisht1054 9 ай бұрын
Thanku bhaiya ❤
@codestorywithMIK
@codestorywithMIK 9 ай бұрын
Thank you 😊
@mdsharique2426
@mdsharique2426 9 ай бұрын
Thanku sir!
@codestorywithMIK
@codestorywithMIK 9 ай бұрын
Glad I could help ♥️♥️
@samannwaysil4412
@samannwaysil4412 9 ай бұрын
God!
@codestorywithMIK
@codestorywithMIK 9 ай бұрын
🙏🙏🙏❤️❤️❤️
@dayashankarlakhotia4943
@dayashankarlakhotia4943 9 ай бұрын
Public class solution { Public int Candy(int []ratings){ int n=ratings. length; int up count =0,down count =0,peak count=0,candy=1; for(int i=1;i
@dayashankarlakhotia4943
@dayashankarlakhotia4943 9 ай бұрын
class solution { public int Candy(int []ratings){ int n=ratings. length; int[]candies =new int [n]; Array. fill (candies,1); for(int i=1;iratings [i-1]){ candies [i]=candies [i-1]+1; } } int count =candies [n-1]; for(int i=n-2;i>=0;i--){ if(ratings [i]>ratings [i+1]){ candies [i]=MATH.MAX (candies [i],candies [i+1]+1); } count +=candies [i]; } return count; } };
@floatingpoint7629
@floatingpoint7629 9 ай бұрын
thanks for the explanation. incase any is looking for bruteforce solution: public class Solution { public int candy(int[] ratings) { int[] candies = new int[ratings.length]; Arrays.fill(candies, 1); boolean hasChanged = true; while (hasChanged) { hasChanged = false; for (int i = 0; i < ratings.length; i++) { if (i != ratings.length - 1 && ratings[i] > ratings[i + 1] && candies[i] 0 && ratings[i] > ratings[i - 1] && candies[i]
@codestorywithMIK
@codestorywithMIK 9 ай бұрын
Thank you 🙏😇
@Vishal-ds6ly
@Vishal-ds6ly 9 ай бұрын
thankyou bhaiya
@codestorywithMIK
@codestorywithMIK 9 ай бұрын
Thank you 😇❤️
@anuppal3243
@anuppal3243 9 ай бұрын
Bhaiya weekly contest ka videos bhi jaldi lao
@codestorywithMIK
@codestorywithMIK 9 ай бұрын
Will soon plan. ❤️❤️❤️
@abhimanyuambastha2595
@abhimanyuambastha2595 12 күн бұрын
Confusing explanation on the part where there is a dip.
@prakharverma8524
@prakharverma8524 9 ай бұрын
bhaiya leetcode ke question ki aur github ki link kal wale question ki daal di hai apne ... please fix it
@codestorywithMIK
@codestorywithMIK 9 ай бұрын
Thanks. Let me fix it
@codestorywithMIK
@codestorywithMIK 9 ай бұрын
Done. Thank you 🙏❤️
@ridj41
@ridj41 4 ай бұрын
2nd approach wasn't clearly explained and caused a lot of confusion
@codestorywithMIK
@codestorywithMIK 4 ай бұрын
Apologies if there were confusion. Would you kindly point where exactly i lost you ? I’ll try my best to explain here ❤️🙏
когда повзрослела // EVA mash
00:40
EVA mash
Рет қаралды 3,4 МЛН
⬅️🤔➡️
00:31
Celine Dept
Рет қаралды 52 МЛН
Пробую самое сладкое вещество во Вселенной
00:41
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 288 М.
Insert Delete GetRandom O(1) | Detailed | Google | Leetcode 380
21:24
codestorywithMIK
Рет қаралды 7 М.
Sum of Subarray Minimums | Detailed | Leetcode 907
49:39
codestorywithMIK
Рет қаралды 19 М.
One Effective Trick to Learn Coding Fast (Works in 2024)
4:53
CodeWithHarry
Рет қаралды 255 М.
когда повзрослела // EVA mash
00:40
EVA mash
Рет қаралды 3,4 МЛН