MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / Solution

Class Solution

FindTheStudentThatWillReplaceTheChalk.java:2–17  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1// maths
2class Solution {
3 public int chalkReplacer(int[] chalk, int k) {
4 long sum=0;
5 for(int i=0;i<chalk.length;i++){
6 sum+=chalk[i];
7 }
8 int remainingChalks = (int)(k % sum);
9 for(int i=0;i<chalk.length;i++){
10 if(remainingChalks < chalk[i]){
11 return i;
12 }
13 remainingChalks -= chalk[i];
14 }
15 return -1;
16 }
17}
18
19// binary search
20class Solution {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected