Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c7c487f

Browse files
committed
Add solution #1701
1 parent 0b7a841 commit c7c487f

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,485 LeetCode solutions in JavaScript
1+
# 1,486 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1310,6 +1310,7 @@
13101310
1696|[Jump Game VI](./solutions/1696-jump-game-vi.js)|Medium|
13111311
1697|[Checking Existence of Edge Length Limited Paths](./solutions/1697-checking-existence-of-edge-length-limited-paths.js)|Hard|
13121312
1700|[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|
13131314
1716|[Calculate Money in Leetcode Bank](./solutions/1716-calculate-money-in-leetcode-bank.js)|Easy|
13141315
1718|[Construct the Lexicographically Largest Valid Sequence](./solutions/1718-construct-the-lexicographically-largest-valid-sequence.js)|Medium|
13151316
1726|[Tuple with Same Product](./solutions/1726-tuple-with-same-product.js)|Medium|
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
};

0 commit comments

Comments
 (0)