Created
January 22, 2018 01:04
-
-
Save jianminchen/98909a6cf985d03dc984dda6ce8514b1 to your computer and use it in GitHub Desktop.
Common intervals - mock interview - 4 PM 1/21/2018 -
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
class Solution | |
{ | |
public static int[] MeetingPlanner(int[,] slotsA, int[,] slotsB, int dur) | |
{ | |
int size=slotsA.Length + slotsB.Length; | |
var output = new int[2]; | |
for(int i = 0; i < size; i++) | |
{ | |
for(int j= 0; j < slotsB.Length; j++) | |
{ | |
int slotsBStart = slotsB[i, 0]; | |
int slotsAStart = slotsA[i, 0]; | |
if(slotsAStart == slotsBStart && (slotsA[i, 1] - slotsA[i,0] >= dur) && (slotsB[i, 1] - slotsBStart >= dur)) | |
{ | |
output[0] = slotsA[i,0]; | |
output[1] = output[0] + dur; | |
} | |
else | |
{ | |
return null; | |
} | |
} | |
} | |
return new int[0]; | |
} | |
static void Main(string[] args) | |
{ | |
} | |
} | |
/* | |
Julia asked the peer about the common interval between two time slots: | |
case A | |
slotsA | |
____________________ | |
slotsB | |
____________ | |
or case B | |
slotsA | |
________ | |
slotsB | |
_______________ | |
or case C | |
slotsA | |
_____ | |
slotsB | |
__________ | |
or case D | |
_________ | |
_______ | |
or case E | |
_________ | |
______________ | |
couter example: | |
__________________________________ | |
5 8 2 | |
__________ __________ _______ | |
slotsA [10, 15], | |
slotsB [0, 15], both common interval has [10, 15] | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment