Skip to content

Commit 1e5c462

Browse files
authoredMar 7, 2023
Create 1894. Find the Student that Will Replace the Chalk
1 parent a0c77ba commit 1e5c462

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution {
2+
public:
3+
int chalkReplacer(vector<int>& chalk, int k) {
4+
5+
long sum=0;
6+
for(int i=0; i<chalk.size(); i++)
7+
{
8+
sum+=chalk[i];
9+
}
10+
k=k%sum;
11+
int i=0;
12+
13+
while(1)
14+
{
15+
if(chalk[i]>k)
16+
return i;
17+
18+
k=k-chalk[i];
19+
i++;
20+
21+
}
22+
return i;
23+
}
24+
};

0 commit comments

Comments
 (0)