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

Method ceil

FindTheStudentThatWillReplaceTheChalk.java:22–38  ·  view source on GitHub ↗
(long prefixSum[], int remainingChalks)

Source from the content-addressed store, hash-verified

20class Solution {
21 int n;
22 public int ceil(long prefixSum[], int remainingChalks){
23 int start = 0;
24 int end = n-1;
25 int ans=0;
26 while(start<=end){
27 int mid = start + (end-start)/2;
28 if(prefixSum[mid] == remainingChalks){
29 return mid+1;
30 }else if(prefixSum[mid] < remainingChalks){
31 start = mid+1;
32 }else{
33 ans = mid;
34 end = mid-1;
35 }
36 }
37 return ans;
38 }
39 public int chalkReplacer(int[] chalk, int k) {
40 n = chalk.length;
41 long prefixSum[] = new long[n];

Callers 3

chalkReplacerMethod · 0.95
maxKelementsMethod · 0.80
countRevMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected