Amazon Interview Question
SDE-2sTeam: Robotics
Country: United States
Interview Type: In-Person
Add 2 array, one for start & other for end. Sort both the arrays.
starting from end index=0, compare the start time with end idx time.
int[] start=new int[array.Length];
int[] end=new int[array.Length];
for(int i=0;i< array.Length;i++)
{
start[i]=array[i][0];
end[i]=array[i][1];
}
Array.Sort(start);
Array.Sort(end);
int numofVM=0;
for (int i=0;i<array.Length;i++ )
{
If (start[i]<=end[endidx] )
numofVM++;
else
endidx+1;
}
return numofVM;
- gemini May 24, 2019