Skip to content

Commit 94a491f

Browse files
add 1701
1 parent 282323a commit 94a491f

File tree

3 files changed

+55
-0
lines changed
  • paginated_contents/algorithms/2nd_thousand
  • src

3 files changed

+55
-0
lines changed

paginated_contents/algorithms/2nd_thousand/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
| 1708 | [Largest Subarray Length K](https://leetcode.com/problems/largest-subarray-length-k/) | [Solution](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/secondthousand/_1708.java) || Easy | Array, Greedy |
123123
| 1705 | [Maximum Number of Eaten Apples](https://leetcode.com/problems/maximum-number-of-eaten-apples/) | [Solution](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/secondthousand/_1705.java) || Medium | Heap, Greedy |
124124
| 1704 | [Determine if String Halves Are Alike](https://leetcode.com/problems/determine-if-string-halves-are-alike/) | [Solution](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/secondthousand/_1704.java) || Easy | String |
125+
| 1701 | [Average Waiting Time](https://leetcode.com/problems/average-waiting-time/) | [Solution](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/secondthousand/_1701.java) || Medium | Array |
125126
| 1700 | [Number of Students Unable to Eat Lunch](https://leetcode.com/problems/number-of-students-unable-to-eat-lunch/) | [Solution](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/secondthousand/_1700.java) || Easy | Array |
126127
| 1695 | [Maximum Erasure Value](https://leetcode.com/problems/maximum-erasure-value/) | [Solution](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/secondthousand/_1695.java) || Medium | Two Pointers |
127128
| 1694 | [Reformat Phone Number](https://leetcode.com/problems/reformat-phone-number/) | [Solution](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/secondthousand/_1694.java) || Easy | String |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.fishercoder.solutions.secondthousand;
2+
3+
public class _1701 {
4+
public static class Solution1 {
5+
/**
6+
* A simple one-pass, just simulate what the problem describes.
7+
*/
8+
public double averageWaitingTime(int[][] customers) {
9+
long totalWaitTime = customers[0][1];
10+
int chefFinishTime = customers[0][0] + customers[0][1];
11+
for (int i = 1; i < customers.length; i++) {
12+
int arrival = customers[i][0];
13+
int prep = customers[i][1];
14+
if (chefFinishTime < arrival) {
15+
chefFinishTime = arrival;
16+
}
17+
chefFinishTime += prep;
18+
totalWaitTime += chefFinishTime - arrival;
19+
}
20+
return (double) totalWaitTime / customers.length;
21+
}
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.fishercoder.secondthousand;
2+
3+
import com.fishercoder.solutions.secondthousand._1701;
4+
import org.junit.jupiter.api.BeforeEach;
5+
import org.junit.jupiter.api.Test;
6+
7+
import static junit.framework.TestCase.assertEquals;
8+
9+
public class _1701Test {
10+
private static _1701.Solution1 solution1;
11+
private static int[] A;
12+
13+
@BeforeEach
14+
public void setup() {
15+
solution1 = new _1701.Solution1();
16+
}
17+
18+
@Test
19+
public void test1() {
20+
assertEquals(5.0, solution1.averageWaitingTime(new int[][]{
21+
{1, 2}, {2, 5}, {4, 3}
22+
}));
23+
}
24+
25+
@Test
26+
public void test2() {
27+
assertEquals(3.25, solution1.averageWaitingTime(new int[][]{
28+
{5, 2}, {5, 4}, {10, 3}, {20, 1}
29+
}));
30+
}
31+
}

0 commit comments

Comments
 (0)