You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jun 26, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: competition/donuts/prob.md
+16-8Lines changed: 16 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ points = 20
11
11
difficulty = 2
12
12
---
13
13
14
-
##🍩 Homer's Donut Run
14
+
# 🍩 Homer's Donut Run
15
15
16
16
Homer Simpson is on a mission to visit a series of **Krispy Kreme** locations arranged in a circle. Each Krispy Kreme offers a certain number of **donuts** for him to collect. However, running between locations costs him some of his precious supply, as Homer **eats donuts for energy while running**. If he runs out of donuts at any point, he'll **collapse** from exhaustion.
17
17
@@ -26,7 +26,20 @@ Your task is to pinpoint the **starting Krispy Kreme's index** that allows Homer
26
26
27
27
Rest assured, there's at most one valid starting point.
28
28
29
-
**Example 1:**
29
+
## Input
30
+
31
+
The input prompt for this question will be 10 rows of numbers,
32
+
representing 5 test cases.
33
+
In each pair of lines of the input prompt,
34
+
the first line in the pair represents the number of donuts at each house,
35
+
while the second line in the pair represents the cost of journeying out of the respective house.
36
+
37
+
### Constraints:
38
+
39
+
*`1 <= donuts.length == cost.length <= 1000`
40
+
*`0 <= donuts[i], cost[i] <= 1000`
41
+
42
+
### Example 1:
30
43
31
44
Input: `donuts = [1,2,3,4]`, `cost = [2,2,4,1]`
32
45
Output: `3`
@@ -39,7 +52,7 @@ Explanation: If Homer starts at Krispy Kreme 3 (index 3) and grabs 4 donuts:
39
52
* Runs to Krispy Kreme 3, eating 4 donuts. His stomach: 5 - 4 + 4 (from station 3) = 5 donuts.
40
53
Homer makes it back to his starting point with donuts to spare, successfully avoiding a collapse!
41
54
42
-
**Example 2:**
55
+
### Example 2:
43
56
44
57
Input: `donuts = [1,2,3]`, `cost = [2,3,2]`
45
58
Output: `-1`
@@ -49,8 +62,3 @@ Homer can't start at Krispy Kreme 0 or 1, because he wouldn't have enough donuts
49
62
If he starts at Krispy Kreme 2, he can run to Krispy Kreme 0, and then Krispy Kreme 1.
50
63
At Krispy Kreme 1, his stomach: 0 + 3 (from station 2) - 2 (eaten to 0) + 1 (from station 0) - 2 (eaten to 1) = 0 donuts.
51
64
He's now stuck at Krispy Kreme 1 with an empty stomach. Without any donuts to power him, he'll collapse right there and won't complete the circuit. D'oh!
0 commit comments