Amazon Interview Question for Software Engineer / Developers






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

@bytestorm: your analysis is wrong. Youngify is called (N*N)/2 times. Hence complexity would be O(N^3) in that way.

Simpler is to read all elements to an O(N^2) sized array, and running median-of-median. Complexity O(N^2).

K-way merging is another option, that would be O(N^2 logN) complexity.

- lol September 05, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

@lol:
Using an extra array is a direct approach, but YOUNGIFY...is no doubt a very good concept...infact a new concept.

- Shwetank September 05, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I agree, although it's not completely "new method"... it's just a derivation of HEAPIFY procedure in MIN/MAX heap.

I mentioned all three methods just to convey the interviewer that you know many ways to solve it. Most interviewers expect time-versus-space trade offs to develop an algorithm. First method needs extra O(n^2) space which reduces time by O(n) factor.

- lol September 05, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I agree with u....but on the other side...K way merging approach is just the another form of HEAPIFY, with a disadvantage...that, we cannot use the information of sorted columns(for K way merging we can look in to the array as either row sorted or column sorted but not both)

- Learner September 05, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Adding to the suggested algorithm of calling youngify, I think we can reduce the number of YOngify calls.
Suppose we have a 5X5 Matrix. The median will have 12 keys less than itself, hence we can replace all the elements that are to the right and bottom of i = 4 and j = 3 (i and j are 0 1 2....) with infinity right at the beginning. So a youngify will run faster every time.
i = 4 and j = 3 because, for i=3 and j=2 we already have 4 * 3 = 12 elements which are for sure lesser.
On a bigger matrix i think it will save a lot of time because whn u do an extractMin and replace it with infinity, this infinity needs to travel shorter distance now.

- anyno September 18, 2011 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Read this: lyle.smu.edu/~saad/courses/cse3358/ps5/problemset5sol.pdf
Call YOUNGIFY n/2 times. Time complexity: N^2

- bytestorm September 04, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Thanks bytestream for this paper link....its really helpful :)

- Shwetank September 04, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@anonymous:
Can u plz replicate ur thought process here:
Queries:
- Every time u extract an element from the matrix...u have to call YOUNGIFY(an O(N) operation)..to restore properties of the matrix.
- How r u moving at the diagonal path as every time u have to extract element from A[0][0] only.
Can u plz give us the trace of ur algoritm....it would be helpful.

- Shwetank September 07, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Using the YOUNGIFY logic, the question becomes finding the median of the diagonal N elements( from place [0,N] to [n,0]), and using RANDOMIZED SELECT we can do that in O(N).

- Anonymous September 06, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Apparently, u r not convinced urself to this solution. Then why need to post some shits over here!

If u dare to challenge, provide full solution. The lowest achievable time for this problem is O(n^2).

- anon September 08, 2011 | Flag


Add a Comment
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.

Learn More

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.

Learn More

Resume Review

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.

Learn More

Mock Interviews

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.

Learn More