File tree Expand file tree Collapse file tree 2 files changed +39
-1
lines changed Expand file tree Collapse file tree 2 files changed +39
-1
lines changed Original file line number Diff line number Diff line change 1- # 1,485 LeetCode solutions in JavaScript
1+ # 1,486 LeetCode solutions in JavaScript
22
33[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
44
131013101696|[ Jump Game VI] ( ./solutions/1696-jump-game-vi.js ) |Medium|
131113111697|[ Checking Existence of Edge Length Limited Paths] ( ./solutions/1697-checking-existence-of-edge-length-limited-paths.js ) |Hard|
131213121700|[ Number of Students Unable to Eat Lunch] ( ./solutions/1700-number-of-students-unable-to-eat-lunch.js ) |Easy|
1313+ 1701|[ Average Waiting Time] ( ./solutions/1701-average-waiting-time.js ) |Medium|
131313141716|[ Calculate Money in Leetcode Bank] ( ./solutions/1716-calculate-money-in-leetcode-bank.js ) |Easy|
131413151718|[ Construct the Lexicographically Largest Valid Sequence] ( ./solutions/1718-construct-the-lexicographically-largest-valid-sequence.js ) |Medium|
131513161726|[ Tuple with Same Product] ( ./solutions/1726-tuple-with-same-product.js ) |Medium|
Original file line number Diff line number Diff line change 1+ /**
2+ * 1701. Average Waiting Time
3+ * https://leetcode.com/problems/average-waiting-time/
4+ * Difficulty: Medium
5+ *
6+ * There is a restaurant with a single chef. You are given an array customers, where
7+ * customers[i] = [arrivali, timei]:
8+ * - arrivali is the arrival time of the ith customer. The arrival times are sorted in
9+ * non-decreasing order.
10+ * - timei is the time needed to prepare the order of the ith customer.
11+ *
12+ * When a customer arrives, he gives the chef his order, and the chef starts preparing it once
13+ * he is idle. The customer waits till the chef finishes preparing his order. The chef does not
14+ * prepare food for more than one customer at a time. The chef prepares food for customers in
15+ * the order they were given in the input.
16+ *
17+ * Return the average waiting time of all customers. Solutions within 10-5 from the actual
18+ * answer are considered accepted.
19+ */
20+
21+ /**
22+ * @param {number[][] } customers
23+ * @return {number }
24+ */
25+ var averageWaitingTime = function ( customers ) {
26+ let totalWait = 0 ;
27+ let currentTime = 0 ;
28+
29+ for ( const [ arrival , prepTime ] of customers ) {
30+ const startTime = Math . max ( arrival , currentTime ) ;
31+ const finishTime = startTime + prepTime ;
32+ totalWait += finishTime - arrival ;
33+ currentTime = finishTime ;
34+ }
35+
36+ return totalWait / customers . length ;
37+ } ;
You can’t perform that action at this time.
0 commit comments