-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTroubleFiles.java
More file actions
59 lines (51 loc) · 1.77 KB
/
Copy pathTroubleFiles.java
File metadata and controls
59 lines (51 loc) · 1.77 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package JavaCodeFightBot.datto;
public class TroubleFiles {
private static final int[][] file01 = {{461618501,3},
{461618502,1},
{461618504,2},
{461618506,5},
{461618507,6}};
private static final int[] backup01 = {461618501, 461618502, 461618504, 461618505, 461618506};
public static void main(String[] args) {
int[] out = troubleFiles(file01, backup01);
System.out.println(" Result ");
for (int i: out) {
System.out.print(i + " ");
}
}
static int[] troubleFiles(int[][] files, int[] backups) {
if (backups == null || backups.length == 0)
return null;
int[] troubleFileByBackup = new int[backups.length];
for (int i = 0; i < backups.length; ++i)
troubleFileByBackup[i] = 0;
if (files == null || files.length == 0)
return troubleFileByBackup;
boolean[] availableMarker = new boolean[files.length];
for (int i = 0; i < files.length; ++i) {
availableMarker[i] = true;
}
int nthFile = 0;
for (int i = 0; i < backups.length; ++i) {
// Count Available File
int totalFileSize = 0;
while (nthFile < files.length && files[nthFile][0] <= backups[i]) {
if (availableMarker[nthFile]) {
totalFileSize += files[nthFile][1];
availableMarker[nthFile] = false;
}
++nthFile;
}
// Count Totol Time neeeded
int completepMoment = backups[i] + totalFileSize;
// Check if files will be added during the the process and mark them as troublemaker
while (nthFile < files.length && files[nthFile][0] <= completepMoment) {
availableMarker[nthFile] = false;
++troubleFileByBackup[i];
++nthFile;
}
// return trouble number of trouble file
}
return troubleFileByBackup;
}
}