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
@monikavaid50836 ай бұрын
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!
@adritaadi80276 ай бұрын
you are so underrated bro!! thanks for making my leetcode journey easier
@davidmiller8146 ай бұрын
Thought of sliding window on the first minute of thinking, all thanks to you sir
@ActorSidhantBhat6 ай бұрын
Amazing work sir app bhaut badiya samjhate ho varnah sabh hindi-urdu bolne wale toh angreez banne kai chakkar mai hai
@justanuhere6 ай бұрын
did this on my own but it took 305ms. thank you so much for your solution.
@PratyushBirole6 ай бұрын
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
@bunnypubg34756 ай бұрын
Pehle 6 min mei hi Moot dia mere approach par
@gui-codes6 ай бұрын
🤣🤣🤣 are bhai
@25-cse-csmohitkumarmandal596 ай бұрын
Bs bhaii🤣🤣🤣
@vanshgambhir78056 ай бұрын
Itna sach nhi bolna tha bhai 😂😂
@DevOpskagyaan6 ай бұрын
😂😂😂
@Polly101896 ай бұрын
Hahah... Ak dam se approach badal di, example badal diya... Waqt badal diya...jazzbat badal diye😂😂😂😂
@gouravshaw69396 ай бұрын
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)
@gouravshaw69396 ай бұрын
wonderful explanation thanks!! I was able to do this on my own after watching the explanation!!
@musaddikkhan97206 ай бұрын
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 💝💝
@musaddikkhan97206 ай бұрын
and i Solved that problem using sliding window also SatisfyCustomer + maximumUnsatisfyCustomer in that minutes window
@musaddikkhan97206 ай бұрын
@@utkpal First pada Love Babbar then From Priyansh agarwal and abhi iss channel se
@bombblaster69456 ай бұрын
just love your explaination...❤Crystal Clear
@nishantkshirsagar21506 ай бұрын
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
@pranavpranjal27176 ай бұрын
Solved this one on my own today!
@tharunkumar81336 ай бұрын
Excellent explanation!! Appreciate your daily efforts!!
@vishalvishwakarma76216 ай бұрын
I don't believe this is same solution that i have implemented 😮
@THOSHI-cn6hg3 ай бұрын
similar to find longest subarray of 1s by filpping k 0s
@imPriyansh776 ай бұрын
Crystal clear explanation!!! Thanks bhaiya...
@thecuriouskid58286 ай бұрын
Thank you sir! Suggestion/Request: Can you also start providing weekly leetcode contest solutions?
@imPriyansh776 ай бұрын
6:17 bhaiya maine yahi socha tha lekin phir galti mil gyi iss approach mai 🥲🥲🥲🥲
@lostcyrus85786 ай бұрын
kya he explanation dete ho bhaiya 😍😍. Segment tree ki new video jaldi lao na please waiting for it.
@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-csmohitkumarmandal596 ай бұрын
Can't believe,it is solved by me without watching your video 😍😍😍🤯🤯❤️❤️🎉🎉🎉
@krishangbose65846 ай бұрын
well taught👏👏👏👏
@abhisheksingh37956 ай бұрын
Just wow❤🔥❤🔥
@Abhay146 ай бұрын
great explaination bhaiya
@rushabhladdha46946 ай бұрын
Holy shit man. I was making it so complex
@Sumit-wy4zp6 ай бұрын
Please upload the next lecture on segment trees. Also, sir, could you provide some LeetCode questions that we can practice?
@motives7486 ай бұрын
Waiting for your video
@varunpalsingh38226 ай бұрын
Today I solved this on my own, using sliding window algorithm 😊
@aggarwalsachin48546 ай бұрын
ab tu nakuri lega aur naukar bnega🤣🤣
@varunpalsingh38226 ай бұрын
@@aggarwalsachin4854 शिक्षित बनो, संघर्ष करो
@varunpalsingh38226 ай бұрын
@@aggarwalsachin4854 शिक्षित बन, संघर्ष कर, अपने पिताजी के पैसों पर ज्यादा मत उछल
@mukulkumar51336 ай бұрын
@@aggarwalsachin4854 abe yr tu bhi wahi krega kuch din bad
@RohitKumar-dz8dh6 ай бұрын
Thanks 😊
@viholvishwassinh17096 ай бұрын
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?
@IITians6 ай бұрын
Power consecutive minutes me use honge...sort karne se minutes consecutive nahi rahenge
@nishantkshirsagar21506 ай бұрын
minutes consecutive he to sort karne se order kharab ho raha he
@viholvishwassinh17096 ай бұрын
@@nishantkshirsagar2150 matlab is question Mai order matter karta hai?
@viholvishwassinh17096 ай бұрын
@@IITians pls thoda sa explanation de sakte ho?
@nishantkshirsagar21506 ай бұрын
@@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?
@Anonymousyr6 ай бұрын
subscriber yesterday 52.6K and today 52.9K 👍
@sarveshjoshi69136 ай бұрын
solved by myself today ❤
@dayashankarlakhotia49436 ай бұрын
Good explanation 🎉❤
@siddhantgoyal51037 күн бұрын
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 .
@anshtanwar18136 ай бұрын
Feedback: All you need is to improve the thumbnails and add some intro/outro. May your channel grow to 100k soon
@codestorywithMIK6 ай бұрын
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 ❤️
@anshtanwar18136 ай бұрын
@@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. 💖✌
@codestorywithMIK6 ай бұрын
Noted ❤️❤️
@NiranjanJangirBCH6 ай бұрын
Thanks
@AmanKumar-qz4jz6 ай бұрын
sir aapne bola tha *longest valid parantheses* pe video layenge weekend pe......please bana dena
@DevOpskagyaan6 ай бұрын
DSA legend 🫡
@Chandakshaythakur6 ай бұрын
Bhaiya Please make a playlist on rabin karp and rolling hash problems
@divsworld59256 ай бұрын
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.
@AbhijeetMuneshwar6 ай бұрын
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? 🙇🙏
@rishabhpanesar96216 ай бұрын
i guess you're our indian @NeetcodeIO
@doomhead91096 ай бұрын
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.
@rohitaggarwal87766 ай бұрын
Can’t we just find maximum sub array sum starting with 1?
@mailatkaushal6 ай бұрын
bruteforce got accepted in this question
@dhairyachauhan66226 ай бұрын
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
@gauravbanerjee28986 ай бұрын
Thanks a lot bhaiya ❤❤
@techyou61636 ай бұрын
class Solution { public: int maxSatisfied(vector& customers, vector& grumpy, int minutes) { int n=customers.size(); int sum=0; for(int i=0;i
@chitranshjain97146 ай бұрын
Did my self🎉
@TUSHARKHANDELWAL-i8s6 ай бұрын
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?
@nishantkshirsagar21506 ай бұрын
parso vali video ke niche he
@atharvsoni89616 ай бұрын
Segment Tree video 4, when??
@yashkumar746126 күн бұрын
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
@knowledgepedia69766 ай бұрын
Bahiya 12.06 me logic click ho gaya ...3ms me solve ho gaya .....but khud se kyu ho nahi ho pata😰😰😰😰😰😰
@ShardulPrabhu6 ай бұрын
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-yf7nl6 ай бұрын
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-codes6 ай бұрын
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.
@aggarwalsachin48546 ай бұрын
customer ko nhi, girlfriend ko satisfy kro
@Mainak9086 ай бұрын
Size increase karke
@22gauravkumar706 ай бұрын
Please segment tree continue kijiye
@mohdaqibkhan21356 ай бұрын
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; } };