Amazon Interview Question
SDE-2sTeam: Robotics
Country: United States
is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.
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.
Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.
Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.
This is very famous problem asked by Amazon thousand number of times. It is a min-heap problem.
They also presented once to me like this:
We have a strcat(s1,s2) that is 3rd party function. Every time you run this function, you need to pay cost s1.length()+s2.length() to 3rd party. You have to minimize this cost.
Suppose you have arrayp[ = {3,4,6,9},
If you start adding bigger numbers first, the cost is (9+6) + ((9+6)+4) + ((9+6+4)+3). You can see that 9 occurred most number of times. So, cost is more. Instead, if you start with 2 smallest numbers, cost will be calculated like this:
1. (3+4=7), now we have {7,6,9}
2. Take min 2 from these (6+7)=13, now we have (13,9)
3. Take min. 2 from these. and final sum is 22.
--------------
So, every time it is about taking minimum 2 numbers, adding them and putting the resultant sum back in set (or array). Again find 2 min. numbers, add them...
Repeat this process until you have a single element (or let's say you have 2 elements and sum them.).
So, algo goes like this:
- alanturing06022014 May 14, 2019