-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPainters Partition.java
More file actions
33 lines (33 loc) · 1008 Bytes
/
Copy pathPainters Partition.java
File metadata and controls
33 lines (33 loc) · 1008 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
static long minTime(int[] arr,int n,int k){
int low = 0, high = 0;
//low hold the value of the highest length board while high will hold the length of all the board
for (int e : arr) {
high += e;
low = Math.max(low, e);
}
long ans = 0;
while (low <= high) {
int mid = low + (high - low) / 2;
if (isFeasible(arr, mid, k)) {
ans = mid;
high = mid - 1;
}
else low = mid + 1;
}
return ans;
}
//Function to check if the k time is possible to get job done by n no of worker
public static boolean isFeasible(int[] arr, int time, int n) {
int count = 1;
int totalTime = 0;
for (int e : arr) {
if (totalTime + e <= time) {
totalTime += e;
}
else {
totalTime = e;
count++;
}
}
return count <= n;
}