Skip to content

Commit c9f3f0d

Browse files
My solution for 1894
1 parent 6680e11 commit c9f3f0d

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

problems/1894/jeremymanning.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,30 @@
11
# [Problem 1894: Find the Student that Will Replace the Chalk](https://leetcode.com/problems/find-the-student-that-will-replace-the-chalk/description/?envType=daily-question)
22

33
## Initial thoughts (stream-of-consciousness)
4+
- I think there are basically two steps to this:
5+
- First, skip ahead to the last "cycle" through the students. To do this, we can set `k %= sum(chalk)`.
6+
- Then we just need to loop through students one at a time until the amount of chalk used is greater than `k`. Or we could also just subtract `chalk[i]` as we loop through each student `i`, and then return `i` when `k` dips below 0. This might be slightly better, since it means we can use one fewer variable.
47

58
## Refining the problem, round 2 thoughts
9+
- I don't see any obvious edge cases here; I think I'm good to implement this
10+
- Not totally sure why this is a "medium" problem; it seems pretty straightforward. Maybe I'm missing something...
611

712
## Attempted solution(s)
813
```python
9-
class Solution: # paste your code here!
10-
...
14+
class Solution:
15+
def chalkReplacer(self, chalk: List[int], k: int) -> int:
16+
k %= sum(chalk)
17+
for i, c in enumerate(chalk):
18+
k -= c
19+
if k < 0:
20+
return i
1121
```
22+
- Given test cases pass
23+
- I'll make up one test case:
24+
- `chalk = [5,1,5,7,2,34,54,76,1,7,34,25,6,9], k = 1005`: pass
25+
- Submitting...
26+
27+
![Screenshot 2024-09-01 at 11 11 40 PM](https://github.com/user-attachments/assets/b9528a9b-81cd-4390-b8c7-be727655010b)
28+
29+
Solved!
30+

0 commit comments

Comments
 (0)