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.
Each machine needs to be able to
(a) Sort the numbers:
(b) Given a value x, return the number of elements < x, == x, > x.
(c) Given indexes begin and last, return a median of the values between begin & last (inclusive).
All 3 need additional constant space which should be OK.
Now, the master machine will keep values begin[i] and last[i] for each machine (and 3 more for temporary storage). (2+3)*N = O(n) data.
Algorithm:
Note that at each step, we are either increasing begin[i] or decreasing last[i] and therefore the pool of possible values is being reduced. This is because the new x is picked from values that are bigger than x_s and smaller than x_b, where x_s is the most recent x that was too small and x_b is the most recent x that was too big.
- czpete October 11, 2010The biggest concern here is obviously the space and there we used O(N) per machine as required.
The running time is something like
O(N*log_N) for sorting in paralel on all machines (Heapsort, no extra space)
+
O(N*log_N) for partitioning
-- We have total of O(log_n) iterations, at least on average. In each iteration, each machine will take at most O(n) time to return smaller[i], equal[i], and bigger[i] in parallel, plus we need to add these and assign new begin/last which also is O(n).
Total = O(N*log_N) time, O(N) space per machine.