Grumpy Bookstore Owner | Simplest Thought Process | Leetcode 1052 | codestorywithMIK

  Рет қаралды 9,696

codestorywithMIK

codestorywithMIK

Күн бұрын

Пікірлер: 86
@aniketnama8390
@aniketnama8390 3 ай бұрын
Solution by the approach taught by The legend(MIK sir) in his previous videos of sliding window class Solution { public: int maxSatisfied(vector& customers, vector& grumpy, int minutes) { int n = customers.size(); int i = 0; int j = 0; int maxunsatcost = 0; int currunsatcost = 0; int ans = 0; for(int i=0;i
@monikavaid5083
@monikavaid5083 6 ай бұрын
Hi Mike, today I followed your approach of writing brute force first then writing the story for optimized solution and then the code finally. I was able to solve this in first attempt. Thanks a lot for building this power in your solutions. I can now get the intuition from the questions and I am also able to solve medium level questions now on leetcode. god bless you MIK 😇 you are doing a great job!
@adritaadi8027
@adritaadi8027 6 ай бұрын
you are so underrated bro!! thanks for making my leetcode journey easier
@davidmiller814
@davidmiller814 6 ай бұрын
Thought of sliding window on the first minute of thinking, all thanks to you sir
@ActorSidhantBhat
@ActorSidhantBhat 6 ай бұрын
Amazing work sir app bhaut badiya samjhate ho varnah sabh hindi-urdu bolne wale toh angreez banne kai chakkar mai hai
@justanuhere
@justanuhere 6 ай бұрын
did this on my own but it took 305ms. thank you so much for your solution.
@PratyushBirole
@PratyushBirole 6 ай бұрын
You are a legend.. Keep teaching like this. Also one more request. Can you please make an excel sheet for all the important DSA questions that you are teaching us ?I would be great. also we can track our progress
@bunnypubg3475
@bunnypubg3475 6 ай бұрын
Pehle 6 min mei hi Moot dia mere approach par
@gui-codes
@gui-codes 6 ай бұрын
🤣🤣🤣 are bhai
@25-cse-csmohitkumarmandal59
@25-cse-csmohitkumarmandal59 6 ай бұрын
Bs bhaii🤣🤣🤣
@vanshgambhir7805
@vanshgambhir7805 6 ай бұрын
Itna sach nhi bolna tha bhai 😂😂
@DevOpskagyaan
@DevOpskagyaan 6 ай бұрын
😂😂😂
@Polly10189
@Polly10189 6 ай бұрын
Hahah... Ak dam se approach badal di, example badal diya... Waqt badal diya...jazzbat badal diye😂😂😂😂
@gouravshaw6939
@gouravshaw6939 6 ай бұрын
Here is the code -> class Solution { public: int maxSatisfied(vector& customers, vector& grumpy, int minutes) { // we will use sliding window approach here // 1. maxUnsatCust findout // 2. add this to totalSat; int n = customers.size(); int maxUnsatCust = 0; int curUnsatCust = 0; for(int i=0; i O(n) { curUnsatCust += grumpy[i]*customers[i]; } maxUnsatCust=curUnsatCust; // sliding window approach below int i=0; int j=minutes; while(jO(n) curUnsatCust += customers[j]*grumpy[j]; // adding the new element in the window curUnsatCust -= customers[i]*grumpy[i]; // removing the old element in the window i++; j++; maxUnsatCust=max(maxUnsatCust,curUnsatCust); } int totalSat=maxUnsatCust; for(int i=0;i O(n) { if(grumpy[i]==0) totalSat+=customers[i]; } return totalSat; } }; // tc-> O(n) // sc -> O(1)
@gouravshaw6939
@gouravshaw6939 6 ай бұрын
wonderful explanation thanks!! I was able to do this on my own after watching the explanation!!
@musaddikkhan9720
@musaddikkhan9720 6 ай бұрын
Wowww ! and i solved this problem using DP 🤐 and i come here to watch optimized solution and w t h this is the sliding window problem so now i am going to solve it using sliding window 💝💝
@musaddikkhan9720
@musaddikkhan9720 6 ай бұрын
and i Solved that problem using sliding window also SatisfyCustomer + maximumUnsatisfyCustomer in that minutes window
@musaddikkhan9720
@musaddikkhan9720 6 ай бұрын
@@utkpal First pada Love Babbar then From Priyansh agarwal and abhi iss channel se
@bombblaster6945
@bombblaster6945 6 ай бұрын
just love your explaination...❤Crystal Clear
@nishantkshirsagar2150
@nishantkshirsagar2150 6 ай бұрын
I solved this by calculating which subarray will cause the maximum increase in sum rather than finding the subarray with maximum sum but it runs in O(n*m) complexity. Accept ho gaya class Solution: def maxSatisfied(self, customers: List[int], grumpy: List[int], minutes: int) -> int: n = len(customers) all_sum = 0 secret_sum_increase = -1 for i in range(n-minutes+1): j = i+minutes temp = 0 for k in range(i,j): if grumpy[k] == 1: temp += customers[k] secret_sum_increase = max(secret_sum_increase,temp) # O(n * minutes) for a in range(len(customers)): if grumpy[a] == 0: all_sum+= customers[a] #O(n) return all_sum+secret_sum_increase
@pranavpranjal2717
@pranavpranjal2717 6 ай бұрын
Solved this one on my own today!
@tharunkumar8133
@tharunkumar8133 6 ай бұрын
Excellent explanation!! Appreciate your daily efforts!!
@vishalvishwakarma7621
@vishalvishwakarma7621 6 ай бұрын
I don't believe this is same solution that i have implemented 😮
@THOSHI-cn6hg
@THOSHI-cn6hg 3 ай бұрын
similar to find longest subarray of 1s by filpping k 0s
@imPriyansh77
@imPriyansh77 6 ай бұрын
Crystal clear explanation!!! Thanks bhaiya...
@thecuriouskid5828
@thecuriouskid5828 6 ай бұрын
Thank you sir! Suggestion/Request: Can you also start providing weekly leetcode contest solutions?
@imPriyansh77
@imPriyansh77 6 ай бұрын
6:17 bhaiya maine yahi socha tha lekin phir galti mil gyi iss approach mai 🥲🥲🥲🥲
@lostcyrus8578
@lostcyrus8578 6 ай бұрын
kya he explanation dete ho bhaiya 😍😍. Segment tree ki new video jaldi lao na please waiting for it.
@2Deadly_
@2Deadly_ 6 ай бұрын
Another way to doing this class Solution { public: int maxSatisfied(vector& customers, vector& grumpy, int minutes) { int n= customers.size(); int ans=0; for(int i=0;i
@25-cse-csmohitkumarmandal59
@25-cse-csmohitkumarmandal59 6 ай бұрын
Can't believe,it is solved by me without watching your video 😍😍😍🤯🤯❤️❤️🎉🎉🎉
@krishangbose6584
@krishangbose6584 6 ай бұрын
well taught👏👏👏👏
@abhisheksingh3795
@abhisheksingh3795 6 ай бұрын
Just wow❤‍🔥❤‍🔥
@Abhay14
@Abhay14 6 ай бұрын
great explaination bhaiya
@rushabhladdha4694
@rushabhladdha4694 6 ай бұрын
Holy shit man. I was making it so complex
@Sumit-wy4zp
@Sumit-wy4zp 6 ай бұрын
Please upload the next lecture on segment trees. Also, sir, could you provide some LeetCode questions that we can practice?
@motives748
@motives748 6 ай бұрын
Waiting for your video
@varunpalsingh3822
@varunpalsingh3822 6 ай бұрын
Today I solved this on my own, using sliding window algorithm 😊
@aggarwalsachin4854
@aggarwalsachin4854 6 ай бұрын
ab tu nakuri lega aur naukar bnega🤣🤣
@varunpalsingh3822
@varunpalsingh3822 6 ай бұрын
​@@aggarwalsachin4854 शिक्षित बनो, संघर्ष करो
@varunpalsingh3822
@varunpalsingh3822 6 ай бұрын
@@aggarwalsachin4854 शिक्षित बन, संघर्ष कर, अपने पिताजी के पैसों पर ज्यादा मत उछल
@mukulkumar5133
@mukulkumar5133 6 ай бұрын
@@aggarwalsachin4854 abe yr tu bhi wahi krega kuch din bad
@RohitKumar-dz8dh
@RohitKumar-dz8dh 6 ай бұрын
Thanks 😊
@viholvishwassinh1709
@viholvishwassinh1709 6 ай бұрын
maine socha tha ki mai pahle customer array ke hisab se customer aur grumpty ko sort kardunga taki muje customers ke hisab se sorted array mil jaye.and then mai last se traverse karta hua aaung and jaha pe muje grumpy mil jae vaha se mai vo power use karlunga and mere is approach se 1st example mai ans 18 aa raha tha to koi bata sakta hai ki kyu wrong tha?
@IITians
@IITians 6 ай бұрын
Power consecutive minutes me use honge...sort karne se minutes consecutive nahi rahenge
@nishantkshirsagar2150
@nishantkshirsagar2150 6 ай бұрын
minutes consecutive he to sort karne se order kharab ho raha he
@viholvishwassinh1709
@viholvishwassinh1709 6 ай бұрын
@@nishantkshirsagar2150 matlab is question Mai order matter karta hai?
@viholvishwassinh1709
@viholvishwassinh1709 6 ай бұрын
@@IITians pls thoda sa explanation de sakte ho?
@nishantkshirsagar2150
@nishantkshirsagar2150 6 ай бұрын
@@viholvishwassinh1709 consecutive minutes tak wo apna secret power use kar sakt ahe agar tum use sort karoge to conseuctive minutes konse he ye kaisse pata chalega?
@Anonymousyr
@Anonymousyr 6 ай бұрын
subscriber yesterday 52.6K and today 52.9K 👍
@sarveshjoshi6913
@sarveshjoshi6913 6 ай бұрын
solved by myself today ❤
@dayashankarlakhotia4943
@dayashankarlakhotia4943 6 ай бұрын
Good explanation 🎉❤
@siddhantgoyal5103
@siddhantgoyal5103 7 күн бұрын
why in the starting we are finding the unsatisfied customers in the first minutes window using a seperate for loop?? Rather than this we could have kept i and j at 0 and applied sliding window by moving j till minutes and if size of window becomes minutes increasing both i and j .
@anshtanwar1813
@anshtanwar1813 6 ай бұрын
Feedback: All you need is to improve the thumbnails and add some intro/outro. May your channel grow to 100k soon
@codestorywithMIK
@codestorywithMIK 6 ай бұрын
This means a lot. Thank you for the feedback. Feel free to provide some suggestions on what changes should I make in the Thumbnail. Would love to hear. Also in intro and outro, what should I add ❤️
@anshtanwar1813
@anshtanwar1813 6 ай бұрын
​@@codestorywithMIK 1) Your thumbnail have different components like different text, your signature image :). But all things seem to be placed/pasted in little unorganized fashion. Matlab sab milakar ek single componet nahi lagte. 2) For example you can see thumbails of other channels like anuj bhaiya, Aryan mittal, take you forward. most of them use their personal brand, image (Pattern 1- More attractive and catchier) 3) But if you dont like these types of thumbnails you can take inspiration from 3 blue one brown channel, Reducible channel. (Pattern 2- simplicity at its best Maybe you could try more on brand building and stuff. Intro toh aap jo motivation dete ho vohi best hai, thoda background music ke sath testing kar sakte ho I am just a college student with some experience in designing but as your regular viewer just wanted to tell you that I am attracted to a 1) catchy and professional thumbnail 2) the views on the video and 3) if the person is familiar to me or is famous. I know content is the power. But these small things can increase subs and views and eventually take the content to a more audience. 💖✌
@codestorywithMIK
@codestorywithMIK 6 ай бұрын
Noted ❤️❤️
@NiranjanJangirBCH
@NiranjanJangirBCH 6 ай бұрын
Thanks
@AmanKumar-qz4jz
@AmanKumar-qz4jz 6 ай бұрын
sir aapne bola tha *longest valid parantheses* pe video layenge weekend pe......please bana dena
@DevOpskagyaan
@DevOpskagyaan 6 ай бұрын
DSA legend 🫡
@Chandakshaythakur
@Chandakshaythakur 6 ай бұрын
Bhaiya Please make a playlist on rabin karp and rolling hash problems
@divsworld5925
@divsworld5925 6 ай бұрын
Bhaiya please please make a video on leetcode 2659. Make array empty please explain the intuition of this problem . No one has covered it properly i wasnt able to understand the intuition after searching for all resources. I beleive your story to code formula will be able to do it . Please please please bhaiya.
@AbhijeetMuneshwar
@AbhijeetMuneshwar 6 ай бұрын
Respected MIK Sir, May I know what motivates you to deliver such a high quality content with lot of dedication, efforts and with total selflessness for free? 🙇🙏
@rishabhpanesar9621
@rishabhpanesar9621 6 ай бұрын
i guess you're our indian @NeetcodeIO
@doomhead9109
@doomhead9109 6 ай бұрын
one suggestion sir if possible please avoid telling the hint in the start of the video like you mentioned sliding window in the starting of this video. This thing make our mind to focus on one direction only.
@rohitaggarwal8776
@rohitaggarwal8776 6 ай бұрын
Can’t we just find maximum sub array sum starting with 1?
@mailatkaushal
@mailatkaushal 6 ай бұрын
bruteforce got accepted in this question
@dhairyachauhan6622
@dhairyachauhan6622 6 ай бұрын
this is how i did it class Solution { public: int maxSatisfied(vector& customers, vector& grumpy, int minutes) { int n = customers.size(); int j = 0; int i = 0; int sum = 0; int maxSum = 0; int start = -1; int end = -1; while(j < n){ sum += (grumpy[j] == 1)?customers[j]:0; while((j - i + 1) > minutes){ sum -= (grumpy[i] == 1)?customers[i]:0; i++; } if(j-i+1 == minutes && maxSum < sum){ maxSum = sum; start = i; end = j; } j++; } int ans = 0; for(int i = 0;i= start && i
@gauravbanerjee2898
@gauravbanerjee2898 6 ай бұрын
Thanks a lot bhaiya ❤❤
@techyou6163
@techyou6163 6 ай бұрын
class Solution { public: int maxSatisfied(vector& customers, vector& grumpy, int minutes) { int n=customers.size(); int sum=0; for(int i=0;i
@chitranshjain9714
@chitranshjain9714 6 ай бұрын
Did my self🎉
@TUSHARKHANDELWAL-i8s
@TUSHARKHANDELWAL-i8s 6 ай бұрын
again did this on my own , bhaiya kal vali video ke comment mai apne similar type ke q ki list di thi wo ab dikh nhi rhi comments mai ? dlt to nhi krdi?
@nishantkshirsagar2150
@nishantkshirsagar2150 6 ай бұрын
parso vali video ke niche he
@atharvsoni8961
@atharvsoni8961 6 ай бұрын
Segment Tree video 4, when??
@yashkumar7461
@yashkumar7461 26 күн бұрын
class Solution { public: int maxSatisfied(vector& customers, vector& grumpy, int minutes) { int n = customers.size(); int unsatisfied = 0, maxUnsatisfied = 0; int i = 0; for(int j=0; j minutes) { if(grumpy[i] == 1) { unsatisfied -= customers[i]; } i++; } maxUnsatisfied = max(maxUnsatisfied , unsatisfied); } // Calculate total satisfied customers int totalSatisfied = 0; for(int i=0; i
@knowledgepedia6976
@knowledgepedia6976 6 ай бұрын
Bahiya 12.06 me logic click ho gaya ...3ms me solve ho gaya .....but khud se kyu ho nahi ho pata😰😰😰😰😰😰
@ShardulPrabhu
@ShardulPrabhu 6 ай бұрын
Sir meh sirf problem statement samjhne ata hu par first page pr uska type samjh jata hai fir mazha nahi ata solve krne aap please timestamp dal sakte ho kya taki direct mein problem statement pr ja saku first slide skip kr k
@AbhishekJain-yf7nl
@AbhishekJain-yf7nl 6 ай бұрын
Ese agr video dekh kr smjoge to kabhi question pdne ki ability improve nhi hogi.. Khud se try kro.. 1-2 baar pd kar. ..
@gui-codes
@gui-codes 6 ай бұрын
first try reading the Qns and try understanding from the examples on your own. Try 1-2 times. If your really get stuck, then get help. Waise mai most of the times video 1 minutes k baad se start karta hu so that start me topic ka pata na chal sake.
@aggarwalsachin4854
@aggarwalsachin4854 6 ай бұрын
customer ko nhi, girlfriend ko satisfy kro
@Mainak908
@Mainak908 6 ай бұрын
Size increase karke
@22gauravkumar70
@22gauravkumar70 6 ай бұрын
Please segment tree continue kijiye
@mohdaqibkhan2135
@mohdaqibkhan2135 6 ай бұрын
Can someone explain what am i doing wrong. I used max heap for this ques Intuition : shopkeeper wants to be non grumpy when he has more customers in his shop better name for cnt= minute_Used_To_Make_not_grumpy class Solution { public: int maxSatisfied(vector& customers, vector& grumpy, int minutes) { int n=customers.size(); priority_queuepq; for(int i=0;i0 && cnt=minutes) { if(pq.top().second==0) satisfied=pq.top().first; } pq.pop(); } return satisfied; } };
@banadipmudi3186
@banadipmudi3186 6 ай бұрын
thanks
UFC 310 : Рахмонов VS Мачадо Гэрри
05:00
Setanta Sports UFC
Рет қаралды 1,2 МЛН
Netflix Removed React?
20:36
Theo - t3․gg
Рет қаралды 61 М.
7 Outside The Box Puzzles
12:16
MindYourDecisions
Рет қаралды 100 М.