Average Waiting Time | Simple Simulation | Leetcode 1701 | codestorywithMIK

Поділитися
Вставка
  • Опубліковано 12 вер 2024
  • Whatsapp Community Link : www.whatsapp.c...
    This is the 96th Video of our Playlist "Arrays - 1D & 2D : Popular Interview Problems" by codestorywithMIK
    In this video we will try to solve a good simulation problem : Average Waiting Time | Simple Simulation | Leetcode 1701 | 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 : Average Waiting Time | Simple Simulation | Leetcode 1701 | codestorywithMIK
    Company Tags : Will update soon
    My solutions on Github(C++ & JAVA) : github.com/MAZ...
    Leetcode Link : leetcode.com/p...
    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/MAZ...
    Instagram : / codestorywithmik
    Facebook : / 100090524295846
    Twitter : / cswithmik
    Subscribe to my channel : / @codestorywithmik
    ╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
    ║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
    ╠╗║╚╝║║╠╗║╚╣║║║║║═╣
    ╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
    Approach Summary :
    The approach to calculate the average waiting time for customers is as follows:
    Initialization:
    totalWaitTime is initialized to accumulate the total waiting time for all customers.
    currTime is initialized to keep track of the current time as the customers are processed.
    Iterate through Customers:
    Loop through each customer in the given list/array.
    For each customer, extract arrivalTime and cookTime.
    Update Current Time:
    If the currTime is less than the customer's arrivalTime, update currTime to the customer's arrivalTime because the chef will wait for the customer to arrive.
    Calculate Waiting Time:
    Calculate the waiting time for the current customer as currTime + cookTime - arrivalTime.
    Add the waiting time to totalWaitTime.
    Update Current Time After Cooking:
    Increment currTime by cookTime to reflect the time taken to cook the current customer's order.
    Calculate Average Waiting Time:
    Finally, calculate the average waiting time by dividing totalWaitTime by the number of customers n.
    This approach ensures that we account for both the waiting time due to early arrival and the cooking time for each customer, ultimately providing the average waiting time across all customers.
    ✨ 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

КОМЕНТАРІ • 41

  • @AbhijeetMuneshwar
    @AbhijeetMuneshwar 2 місяці тому +18

    Respected MIK Sir,
    I’m learning to be consistent from you 🙏🏼

  • @IronmanDon-my6fw
    @IronmanDon-my6fw 2 місяці тому +20

    It is first come first serve algorithm of operating system

  • @gui-codes
    @gui-codes 2 місяці тому +5

    I was able to solve on my own. After doing some mistakes, it got accepted.
    I am here to thank you for helping me improve my problem solving skills. Thanks a lot MIK

  • @sonakshibajpai6445
    @sonakshibajpai6445 2 місяці тому +4

    i used to be scared of doing POTDs when i started dsa , now the first thing i do is watch your video in the morning thank you!

  • @froglighthouse1223
    @froglighthouse1223 2 місяці тому +9

    Because of you I have started to get better at coding…. If I get placed in the next year you will be the reason for it. Thank you sir

    • @codestorywithMIK
      @codestorywithMIK  2 місяці тому +11

      Means a lot ❤️🙏
      I am sure you will crack the interviews.
      Keep up the consistency and hard work, and no one will stop you

  • @star_Cedric
    @star_Cedric 2 місяці тому +5

    Hey Mik, your explanations are too good.
    Btw, this was my approach -
    class Solution {
    public:
    double averageWaitingTime(vector& customers) {
    int n = customers.size();
    double customersWaitingTime = 0;
    int cookingStartTime = 0;
    int servingTime = 0;

    int i = 0;
    while(i != n){
    cookingStartTime = max(customers[i][0], servingTime);
    servingTime = cookingStartTime + customers[i][1];
    customersWaitingTime += (servingTime - customers[i][0]);
    i++;
    }
    return (customersWaitingTime / n);
    }
    };

  • @darshitgajjar5199
    @darshitgajjar5199 2 місяці тому +1

    You're Really helping the CP community. Big Kudos from my side!!
    .....
    Please make this kind of Video. you motivated us to fight for our Goal

  • @user-ym1nv1pw8i
    @user-ym1nv1pw8i 2 місяці тому +3

    My approach :
    class Solution {
    public:
    double averageWaitingTime(vector& customers) {
    int n = customers.size();
    long long currentTime = customers[0][0];
    long long waitingTime = 0;
    for(auto &vec : customers) {
    if(vec[0] > currentTime){
    currentTime = vec[0];
    }
    currentTime += vec[1];
    waitingTime += (currentTime - vec[0]);
    }
    return (double)(waitingTime)/(n);
    }
    };

  • @kumarsaurabh6207
    @kumarsaurabh6207 2 місяці тому +2

    it is based on FCFS algorithm, we can take a separate array for completion time of orders and then can use the formula waiting time = completion time - arrival time; at last add all waiting times and divide by number of orders or customers.

  • @manasdeora4601
    @manasdeora4601 2 місяці тому +1

    I made the exact same logic and on my own. Though this is easy one, but I am glad that the thought process matched.

  • @rahulkumar-wz9jc
    @rahulkumar-wz9jc 2 місяці тому +1

    Bhaiya yr aap kamaal ho daily morning uthta hu toh dekhta hu ki aapne leetcode ka potd solve krke daal diye toh esse khaafi motivation milti h ki ha bhaiya daale toh krna toh bnta h thnq bhaiya chizon ko etna aasan bnane ke liye

  • @aizad786iqbal
    @aizad786iqbal 2 місяці тому +1

    aaj ka question khud se kar liya... pehle mai itne bade question padh ke ghabra jaata tha..
    your videos help ..
    bas ab series waali playlist start karni ... starting with recurison...
    my code intially failed beacause maine total time etc int mai le liya tha..kuch range ka issue tha I think
    class Solution {
    public double averageWaitingTime(int[][] customers) {
    int n = customers.length;
    double total_time = 0;
    int arrival_time = 0;
    int prepare_time = 0;
    double avg_time= 0;
    for(int[] x : customers){
    arrival_time = x[0];
    prepare_time = x[1];
    if(arrival_time > total_time){
    total_time += (arrival_time - total_time);
    }
    total_time += prepare_time;
    double waiting_time = total_time - arrival_time;
    avg_time += waiting_time;
    }
    return avg_time / n;
    }
    }

  • @ReshuSharma-jc7yu
    @ReshuSharma-jc7yu 2 місяці тому

    Thank You @codestorywithMIK because of you i have completely lost my fear of DSA looking forward for your new playlist of backtracking and heap by the way i have completed this at 5:30 am because of you looking for more guidance with you

  • @factinsaan4333
    @factinsaan4333 2 місяці тому +1

    class Solution {
    public:
    double averageWaitingTime(vector& c) {
    double ans=0.0;
    int n=c.size();
    int start_time=c[0][0];
    int end_time=c[0][1]+start_time;
    long long total=c[0][1];
    for(int i=1;i

  • @syedhamid-ky3su
    @syedhamid-ky3su 2 місяці тому +1

    Based on FCFS algorithm which we studied in operating system

  • @pain9569
    @pain9569 2 місяці тому +2

    Today I completed my 100 Days of Streak
    To be honest earlier I was so bad, I used to take hours and was still not able to solve the problems, in the last 20 days, I am able to solve most of the POTDs on my own, all thanks to you. Because the time I got stuck on a question, you helped me thinking of its approaches from base. Thank you so much Mazhar Bhaiya 😌❤

    • @TheRandomPerson49
      @TheRandomPerson49 2 місяці тому +2

      I just started making streaks. Hope I will achieve this milestone. BTW, Keep it up man 🫡

    • @pain9569
      @pain9569 2 місяці тому +1

      @@TheRandomPerson49 Thanks, best of luck
      Still a lot to achieve 😄

  • @user-hn9ke6ty2g
    @user-hn9ke6ty2g 2 місяці тому +1

    you r a gem sir

  • @gauravbanerjee2898
    @gauravbanerjee2898 2 місяці тому +1

    Thanks a lot bhaiya ❤❤ Congrats for 56k subs 🥳🥳

  • @ugcwithaddi
    @ugcwithaddi 2 місяці тому

    Thank you 😊
    I could do it on my own

  • @user-ub2is4rs4x
    @user-ub2is4rs4x 2 місяці тому

    It was an easy medium. Solved 😍

  • @Shivamsingh-ry6bz
    @Shivamsingh-ry6bz 2 місяці тому +2

    my approach
    class Solution {
    public double averageWaitingTime(int[][] arr) {
    int n=arr.length;
    double sum=arr[0][1];
    int p=arr[0][0]+arr[0][1];
    for(int i=1;i

  • @ayann_nema
    @ayann_nema 2 місяці тому +1

    sir which writing software do you use??

  • @noname-te8nn
    @noname-te8nn 2 місяці тому

    sir please solve count subarray with and value k, it would be very helpful

  • @03_utpallucky40
    @03_utpallucky40 2 місяці тому +3

    class Solution {
    public:
    double averageWaitingTime(vector& customers) {
    double ans=0;
    long long n=customers.size();
    long long waitingTime=customers[0][1];
    int totalTime=customers[0][0]+customers[0][1];
    for(int i=1;i

  • @xyzhacker00999
    @xyzhacker00999 2 місяці тому +1

    good

  • @asimshah1824
    @asimshah1824 2 місяці тому +1

    Funfact this question is the same as FCFS of operating system

  • @tarunsingh2480
    @tarunsingh2480 2 місяці тому

    class Solution {
    public:
    double averageWaitingTime(vector& customers) {
    int n = customers.size();
    double wait=0;
    double time = customers[0][0];
    for(auto &it: customers){
    if(time>=it[0]){
    time+= it[1];
    int x =time-it[0];
    wait+=x;
    }
    else{
    time =it[0];
    time+= it[1];
    int x =time-it[0];
    wait+=x;
    }
    }
    return (wait/n);
    }
    };

  • @ShouryaGupta-nn5ev
    @ShouryaGupta-nn5ev 2 місяці тому

    plzz upload the soln 🙏number of subarray with AND equal to K

  • @HimanshuRaj-w9c
    @HimanshuRaj-w9c 24 дні тому +1

    purely Operating system cpu scheduling problem.

  • @rakeshprajapati9916
    @rakeshprajapati9916 2 місяці тому

    isn't there any good approach for this that takes less time?

  • @shabananoor9423
    @shabananoor9423 2 місяці тому

    ❤❤

  • @main_karan
    @main_karan 2 місяці тому

    ❤❤❤

  • @anupthakur489
    @anupthakur489 2 місяці тому

    my approach
    class Solution {
    public:
    double averageWaitingTime(vector& customers) {
    int finishtime =0;
    int waitingtime=0;
    double sum = 0;
    for(int i = 0;i

  • @dayashankarlakhotia4943
    @dayashankarlakhotia4943 2 місяці тому +1

    public double averageWaitingTime(int[][]customers){
    double wait=0;
    int time=-1;
    for(int[]vec:customers){
    time=(time