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.
how to approach such problem : ?
observations needed
a car can only start and reach at the same point back only and only if it has non negative petrol all the time.
it has infinite capacity so it will take all the petrol that is available to it .
mileage is 1km/ltr which just simplifies the calculation . the amount of petrol in car is equal to the distance it can travel.
line of thought : let car start from any petrol pump and reach the next petrol pump and fill its tank . at this point the car will contain residual petrol from the previous petrol pump and full petrol of current petrol pump. this will keep on happening till it reaches the same petrol pump again or petrol in tank becomes negative.
now let petrol pum capacity = [1, 1, 2, 3 , 1]
and distance between pumps =[2, 1, 1, 1, 3 ]
let there be another array diff=[-1, 0, 1, 2, -2] the difference between 1st and 2nd array { it was allowed to use O(n) space so it was hint that helper array can be used }
if car starts from i-th petrol pump and is currently at j-th petrol pump .. petrol in its tank will be the sum of elements of diff array from i to j . so car will be able to reach its origin point only when the sum of elements from its start point i and end point j ( the last petrol pump) is at least zero.
in this example truck can start from both B and C of petrol pump { A,B,C,D,E
python code based on above
- rohit.nsit08 March 06, 2013