problem
solution
- brute force , TLE
1
2
3
4
5
6
7
8
9
10
11
12class Solution {
public:
int chalkReplacer(vector<int>& chalk, int k) {
// brute force , TLE
int i=0, size = chalk.size();
while(k - chalk[i%size] >= 0){
k -= chalk[i%size];
i++;
}
return i%size;
}
};
option 1 - math to prune
1 | class Solution { |
option 2 - Binary Search
1 | class Solution { |