Skip to content

Commit 5b36c79

Browse files
authored
Create find-the-student-that-will-replace-the-chalk.cpp
1 parent 56c0075 commit 5b36c79

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
int chalkReplacer(vector<int>& chalk, int k) {
7+
k %= accumulate(cbegin(chalk), cend(chalk), 0LL);
8+
for (int i = 0; i < size(chalk); k -= chalk[i++]) {
9+
if (k < chalk[i]) {
10+
return i;
11+
}
12+
}
13+
return -1;
14+
}
15+
};

0 commit comments

Comments
 (0)