Amazon Interview Question for SDE-2s

Team: Robotics
Country: United States
Interview Type: In-Person

Comment hidden because of low score. Click to expand.
1
of 1 vote

``````struct Job
{
int start;
int end;
};

struct JobPoint
{
bool operator<(const JobPoint& p)
{
return time != p.time ? time < p.time : (IsStart && (!p.IsStart));
}

int time;
bool IsStart;
};

int MinimalVMs(const vector<Job>& jobs)
{
vector<JobPoint> jps;
for (const Job& job : jobs)
{
jps.emplace_back(JobPoint{ job.start, true });
jps.emplace_back(JobPoint{ job.end, false });
}

sort(jps.begin(), jps.end());

int max_num = 0, cur_num = 0;
for (int i = 0; i < jps.size(); i++)
{
if (jps[i].IsStart)
{
cur_num++;
max_num = max(max_num, cur_num);
}
else
cur_num--;
}

return max_num;
}``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

put starttime and endtime in one array and sort it ( be able to differentiate which is start and which is end). Scan the array for concurrently running program and keep track of max value for the same. after complete of scan return the max value.

Comment hidden because of low score. Click to expand.
0
of 0 vote

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;``````

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.