i tried the problem Find the Student that Will Replace the Chalk on leetcode.
I thought my solotion should work but there is on test case where it doesnt work and I dont understand why.
Here is the test case.
And here is my Code
class Solution {
public int chalkReplacer(int[] chalk, int k) {
return getChalkReplacer(chalk, k);
}
public int getChalkReplacer(int[] chalk, int remaining_chalk){
int chalk_sum = 0;
for(int i=0; i<chalk.length; i++){
chalk_sum += chalk[i];
if(remaining_chalk - chalk_sum <= 0 || chalk[i] > remaining_chalk){
return i;
}
}
return getChalkReplacer(chalk, remaining_chalk % chalk_sum);
}
}
New contributor
Aprikose is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.