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

Поділитися
Вставка
  • Опубліковано 19 чер 2024
  • Whatsapp Community Link : www.whatsapp.com/channel/0029...
    This is the 23rd Video of our Playlist "Sliding Window : Popular Interview Problems" by codestorywithMIK
    In this video we will try to solve a good and standard Sliding Window Problem : Grumpy Bookstore Owner | Simplest Thought Process | Leetcode 1052 | codestorywithMIK
    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.
    Also, please note that my Github solution link below contains both C++ as well as JAVA code.
    Problem Name : Grumpy Bookstore Owner | Simplest Thought Process | Leetcode 1052 | codestorywithMIK
    Company Tags : will update soon
    My solutions on Github(C++ & JAVA) : github.com/MAZHARMIK/Intervie...
    Leetcode Link : leetcode.com/problems/grumpy-...
    My DP Concepts Playlist : • Roadmap for DP | How t...
    My Graph Concepts Playlist : • Graph Concepts & Qns -...
    My Recursion Concepts Playlist : • Introduction | Recursi...
    My GitHub Repo for interview preparation : github.com/MAZHARMIK/Intervie...
    Instagram : / codestorywithmik
    Facebook : / 100090524295846
    Twitter : / cswithmik
    Subscribe to my channel : / @codestorywithmik
    ╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
    ║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
    ╠╗║╚╝║║╠╗║╚╣║║║║║═╣
    ╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
    Summary :
    The approach used in the provided code to solve the problem of maximizing satisfied customers involves the following steps:
    Initial Calculation:
    Calculate the initial number of unsatisfied customers within the first minutes window. This is done by multiplying the number of customers by the grumpy state for the first minutes elements and summing the results.
    Sliding Window Technique:
    Utilize a sliding window of size minutes to determine the maximum number of unsatisfied customers that can be turned into satisfied customers by leveraging the special technique. As the window slides one position to the right:
    Include the next element's contribution to unsatisfied customers if it falls within the grumpy period.
    Exclude the first element of the previous window.
    Update the maximum number of unsatisfied customers (maxUnsat) that can be converted to satisfied customers within any window of minutes.
    Total Satisfied Customers Calculation:
    Calculate the total number of satisfied customers by adding:
    The maximum number of potentially converted unsatisfied customers (maxUnsat).
    The customers who are already satisfied (i.e., where grumpy[i] is 0).
    By combining these steps, the algorithm efficiently finds the maximum possible number of satisfied customers by utilizing a sliding window technique to optimize the period during which the special technique can be applied.
    ✨ Timelines✨
    00:00 - Introduction
    #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 #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #newyear2024

КОМЕНТАРІ • 83

  • @bunnypubg3475
    @bunnypubg3475 26 днів тому +30

    Pehle 6 min mei hi Moot dia mere approach par

  • @monikavaid5083
    @monikavaid5083 25 днів тому +3

    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!

  • @2Deadly_
    @2Deadly_ 25 днів тому +1

    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

  • @adritaadi8027
    @adritaadi8027 25 днів тому +4

    you are so underrated bro!! thanks for making my leetcode journey easier

  • @user-pr8cv2we9v
    @user-pr8cv2we9v 25 днів тому +1

    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

  • @ActorSidhantBhat
    @ActorSidhantBhat 25 днів тому

    Amazing work sir app bhaut badiya samjhate ho varnah sabh hindi-urdu bolne wale toh angreez banne kai chakkar mai hai

  • @nishantkshirsagar2150
    @nishantkshirsagar2150 25 днів тому +2

    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

  • @dhairyachauhan6622
    @dhairyachauhan6622 25 днів тому +1

    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

  • @davidmiller814
    @davidmiller814 25 днів тому +1

    Thought of sliding window on the first minute of thinking, all thanks to you sir

  • @tharunkumar8133
    @tharunkumar8133 26 днів тому +1

    Excellent explanation!! Appreciate your daily efforts!!

  • @priyanshkumariitd
    @priyanshkumariitd 26 днів тому

    Crystal clear explanation!!! Thanks bhaiya...

  • @Abhay14
    @Abhay14 26 днів тому +2

    great explaination bhaiya

  • @abhisheksingh3795
    @abhisheksingh3795 25 днів тому +1

    Just wow❤‍🔥❤‍🔥

  • @bombblaster6945
    @bombblaster6945 26 днів тому +5

    just love your explaination...❤Crystal Clear

  • @gouravshaw6939
    @gouravshaw6939 26 днів тому +1

    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)

  • @pranavpranjal2717
    @pranavpranjal2717 26 днів тому +3

    Solved this one on my own today!

  • @justanuhere
    @justanuhere 25 днів тому +1

    did this on my own but it took 305ms. thank you so much for your solution.

  • @gouravshaw6939
    @gouravshaw6939 26 днів тому +2

    wonderful explanation thanks!! I was able to do this on my own after watching the explanation!!

  • @lostcyrus8578
    @lostcyrus8578 26 днів тому +2

    kya he explanation dete ho bhaiya 😍😍. Segment tree ki new video jaldi lao na please waiting for it.

  • @krishangbose6584
    @krishangbose6584 26 днів тому +1

    well taught👏👏👏👏

  • @techyou6163
    @techyou6163 26 днів тому

    class Solution {
    public:
    int maxSatisfied(vector& customers, vector& grumpy, int minutes) {
    int n=customers.size();
    int sum=0;
    for(int i=0;i

  • @motives748
    @motives748 26 днів тому +4

    Waiting for your video

  • @dayashankarlakhotia4943
    @dayashankarlakhotia4943 26 днів тому

    Good explanation 🎉❤

  • @RohitKumar-dz8dh
    @RohitKumar-dz8dh 25 днів тому +2

    Thanks 😊

  • @rushabhladdha4694
    @rushabhladdha4694 26 днів тому +1

    Holy shit man. I was making it so complex

  • @sarveshjoshi6913
    @sarveshjoshi6913 26 днів тому

    solved by myself today ❤

  • @vishalvishwakarma7621
    @vishalvishwakarma7621 25 днів тому +1

    I don't believe this is same solution that i have implemented 😮

  • @NiranjanJangirBCH
    @NiranjanJangirBCH 25 днів тому +1

    Thanks

  • @Sumit-wy4zp
    @Sumit-wy4zp 26 днів тому +6

    Please upload the next lecture on segment trees. Also, sir, could you provide some LeetCode questions that we can practice?

  • @musaddikkhan9720
    @musaddikkhan9720 26 днів тому +1

    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 26 днів тому

      and i Solved that problem using sliding window also SatisfyCustomer + maximumUnsatisfyCustomer in that minutes window

    • @codecodecode1752
      @codecodecode1752 26 днів тому

      bhai dp kha se pdha

    • @musaddikkhan9720
      @musaddikkhan9720 26 днів тому

      @@codecodecode1752 First pada Love Babbar then From Priyansh agarwal and abhi iss channel se

  • @gauravbanerjee2898
    @gauravbanerjee2898 26 днів тому

    Thanks a lot bhaiya ❤❤

  • @banadipmudi3186
    @banadipmudi3186 17 днів тому +1

    thanks

  • @priyanshkumariitd
    @priyanshkumariitd 26 днів тому +8

    6:17 bhaiya maine yahi socha tha lekin phir galti mil gyi iss approach mai 🥲🥲🥲🥲

  • @thecuriouskid5828
    @thecuriouskid5828 26 днів тому +1

    Thank you sir!
    Suggestion/Request: Can you also start providing weekly leetcode contest solutions?

  • @varunpalsingh3822
    @varunpalsingh3822 26 днів тому +11

    Today I solved this on my own, using sliding window algorithm 😊

    • @aggarwalsachin4854
      @aggarwalsachin4854 26 днів тому +6

      ab tu nakuri lega aur naukar bnega🤣🤣

    • @varunpalsingh3822
      @varunpalsingh3822 26 днів тому

      ​@@aggarwalsachin4854 शिक्षित बनो, संघर्ष करो

    • @varunpalsingh3822
      @varunpalsingh3822 25 днів тому

      @@aggarwalsachin4854 शिक्षित बन, संघर्ष कर, अपने पिताजी के पैसों पर ज्यादा मत उछल

    • @mukulkumar5133
      @mukulkumar5133 25 днів тому

      @@aggarwalsachin4854 abe yr tu bhi wahi krega kuch din bad

  • @25-cse-csmohitkumarmandal59
    @25-cse-csmohitkumarmandal59 26 днів тому +3

    Can't believe,it is solved by me without watching your video 😍😍😍🤯🤯❤️❤️🎉🎉🎉

  • @AbhijeetMuneshwar
    @AbhijeetMuneshwar 26 днів тому +1

    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?
    🙇🙏

  • @Anonymousyr
    @Anonymousyr 26 днів тому +1

    subscriber yesterday 52.6K and today 52.9K 👍

  • @Chandakshaythakur
    @Chandakshaythakur 26 днів тому

    Bhaiya Please make a playlist on rabin karp and rolling hash problems

  • @doomhead9109
    @doomhead9109 25 днів тому +1

    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.

  • @AmanKumar-qz4jz
    @AmanKumar-qz4jz 26 днів тому

    sir aapne bola tha *longest valid parantheses* pe video layenge weekend pe......please bana dena

  • @mailatkaushal
    @mailatkaushal 25 днів тому +1

    bruteforce got accepted in this question

  • @divsworld5925
    @divsworld5925 26 днів тому

    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.

  • @user-ub2is4rs4x
    @user-ub2is4rs4x 24 дні тому

    DSA legend 🫡

  • @rishabhpanesar9621
    @rishabhpanesar9621 25 днів тому +1

    i guess you're our indian @NeetcodeIO

  • @anshtanwar1813
    @anshtanwar1813 25 днів тому +1

    Feedback: All you need is to improve the thumbnails and add some intro/outro. May your channel grow to 100k soon

    • @codestorywithMIK
      @codestorywithMIK  25 днів тому +1

      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 25 днів тому

      ​@@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  24 дні тому

      Noted ❤️❤️

  • @chitranshjain9714
    @chitranshjain9714 26 днів тому +3

    Did my self🎉

  • @atharvsoni8961
    @atharvsoni8961 26 днів тому

    Segment Tree video 4, when??

  • @rohitaggarwal8776
    @rohitaggarwal8776 25 днів тому

    Can’t we just find maximum sub array sum starting with 1?

  • @user-je1nh6qq7x
    @user-je1nh6qq7x 26 днів тому +1

    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?

  • @viholvishwassinh1709
    @viholvishwassinh1709 26 днів тому +2

    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 25 днів тому

      Power consecutive minutes me use honge...sort karne se minutes consecutive nahi rahenge

    • @nishantkshirsagar2150
      @nishantkshirsagar2150 25 днів тому

      minutes consecutive he to sort karne se order kharab ho raha he

    • @viholvishwassinh1709
      @viholvishwassinh1709 25 днів тому

      @@nishantkshirsagar2150 matlab is question Mai order matter karta hai?

    • @viholvishwassinh1709
      @viholvishwassinh1709 25 днів тому

      @@IITians pls thoda sa explanation de sakte ho?

    • @nishantkshirsagar2150
      @nishantkshirsagar2150 25 днів тому

      @@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?

  • @knowledgepedia6976
    @knowledgepedia6976 26 днів тому

    Bahiya 12.06 me logic click ho gaya ...3ms me solve ho gaya .....but khud se kyu ho nahi ho pata😰😰😰😰😰😰

  • @aggarwalsachin4854
    @aggarwalsachin4854 26 днів тому +1

    customer ko nhi, girlfriend ko satisfy kro

  • @ShardulPrabhu
    @ShardulPrabhu 26 днів тому

    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 26 днів тому +1

      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 26 днів тому +1

      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.

  • @22gauravkumar70
    @22gauravkumar70 26 днів тому

    Please segment tree continue kijiye

  • @mohdaqibkhan2135
    @mohdaqibkhan2135 23 дні тому

    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;
    }
    };