Skip to content

Commit a510c8c

Browse files
Merge remote-tracking branch 'origin/master'
2 parents de927d5 + df8a6ea commit a510c8c

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/main/java/pramp/Interview9

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Given time availabilities for two people and a duration for meeting between them, find the
3+
* earliest available time slot where they can conduct schedule the meeting. If there is no
4+
* such time slot then return an empty array.
5+
*
6+
* @author: shivam.maharshi
7+
*/
8+
class Pramp {
9+
public static void main(String[] args) {
10+
String pramp = "Practice Makes Perfect";
11+
System.out.println(pramp);
12+
}
13+
14+
public static int[] get (int[][] ta, [][] tb, int dur) {
15+
int[] r = new int[2];
16+
if (ta == null || ta.length() == 0 || tb == null || tb.length() ==0)
17+
return r;
18+
int i=0, j=0;
19+
20+
while (i < ta.legnth() && j < tb.length()) {
21+
int start = Math.max(ta[i][0], tb[j][0]), end = Math.min(ta[i][1], tb[j][1]);
22+
if (end - start >= dur) {
23+
r[0] = start;
24+
r[1] = end;
25+
return r;
26+
} else {
27+
if (i == ta.length() -1)
28+
j++;
29+
else if (j == tb.length() - 1)
30+
i++;
31+
else if (ta[i][1] < tb[j][1])
32+
i++;
33+
else
34+
j++;
35+
}
36+
}
37+
return r;
38+
}
39+
}

0 commit comments

Comments
 (0)