Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created January 22, 2018 01:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jianminchen/98909a6cf985d03dc984dda6ce8514b1 to your computer and use it in GitHub Desktop.
Save jianminchen/98909a6cf985d03dc984dda6ce8514b1 to your computer and use it in GitHub Desktop.
Common intervals - mock interview - 4 PM 1/21/2018 -
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