Average Waiting Time | Simple Simulation | Leetcode 1701 | codestorywithMIK
Whatsapp Community Link : https://www.whatsapp.com/channel/0029...
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) : https://github.com/MAZHARMIK/Intervie...
Leetcode Link : https://leetcode.com/problems/average...
My DP Concepts Playlist : • Roadmap for DP | How to Start DP ? | ...
My Graph Concepts Playlist : • Graph Concepts & Qns - 1 : Graph will...
My Recursion Concepts Playlist : • Introduction | Recursion Concepts And...
My GitHub Repo for interview preparation : https://github.com/MAZHARMIK/Intervie...
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