Skip to content

Commit efabd17

Browse files
Create Interview9
1 parent 3a81d9a commit efabd17

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

src/main/java/pramp/Interview9

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
class Pramp {
2+
public static void main(String[] args) {
3+
String pramp = "Practice Makes Perfect";
4+
System.out.println(pramp);
5+
}
6+
7+
timesA = {[1, 3] , [6, 7], [10, 15]}
8+
timesB = {[4, 5] , [6, 11], [12, 20]}
9+
dur = 3;
10+
11+
// 1, 5
12+
// 2, 5
13+
// 3
14+
15+
// n * 2 // m * 2
16+
public static int[] get (int[][] ta, [][] tb, int dur) {
17+
int[] r = new int[2];
18+
if (ta == null || ta.length() == 0 || tb == null || tb.length() ==0)
19+
return r;
20+
int i=0, j=0;
21+
22+
while (i < ta.legnth() && j < tb.length()) {
23+
if (hasSlot(ta[i], tb[j], i, j, dur)) {
24+
r[0] = Math.max(ta[i][0], tb[j][0]); // Start
25+
r[1] = Math.min(ta[i][1], tb[j][1]); // End
26+
return r;
27+
} else {
28+
if (i == ta.length() -1)
29+
j++;
30+
else if (j == tb.length() - 1)
31+
i++;
32+
else if (incrA(ta, tb, i, j))
33+
i++;
34+
else
35+
j++;
36+
}
37+
}
38+
39+
return r;
40+
}
41+
42+
public static boolean hasSlot(int[][] ta, int[][] tb, int i, int j, int dur) {
43+
return Math.min(ta[i][1], tb[j][1]) - Math.max(ta[i][0], tb[j][0]) >= dur;
44+
}
45+
46+
public static boolean incrA(int[][] ta, int[][] tb, int i, int j) {
47+
return ta[i][1] < tb[j][1];
48+
}
49+
50+
}

0 commit comments

Comments
 (0)