Amazon Interview Question for Software Engineer / Developers


Country: India
Interview Type: Phone Interview




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

celebrity problem..
geeksforgeeks.org/archives/19622

- shivirocks2909 October 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

the provided function knows() is different from the standard celebrity problem. This function is insufficient to solve the problem.

Imagine the case of two people, one of them is the celebrity. The knows() is not providing sufficient info.

- Daru October 30, 2012 | Flag
Comment hidden because of low score. Click to expand.
2
of 2 vote

its like storing a directed graph in a matrix. Now the job is to find out the node where its in degree is n-1(no. of people in the room) and out degree is 0

- Srikanth October 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

store each person in stack.

Run loop thru all elements
- Pick top 2 people A and B
- call boolean knows(personA, personB){} ,
If true, Neglect both and pick next two
if false, make two calls by taking next element C
if (boolean knows(personA, personC){}==false) return A
if (boolean knows(personB, personC){} == false) return B

Time : O(n) where n is number of people.

The difference between this problem and celebrity problem is that the function boolean knows(personA, personB){} tells if both know each other and not just A knowing B. So one call is reduced everytime.

- Anonymous October 30, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

any idea to do it in less than n^2 complexity if there please share

- geeks October 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Extremely simple -

[a] say the people are in an array.
[b] Loop for elements in the array such that at each iteration we consider i and i+1 elements(so next iteration we consider i+1 and i+2 elements)
[c] for the elements in an iteration, run knows and if true continue else we have the person in i or i+1 index. If knows(i,i-1) is false then i is the person else i+1 is the person.

End of story :)

Time Complexity: O(n) + complexity of knows function
Space Complexity: O(n) to hold the persons + O(c) for the algo

- sayantan December 19, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

It is given that we have access to the function "knows" only.

Also, how do you know relation between 'i' and 'i+2'?

- Anonymous December 19, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I am using just the knows function in step c in an iteration

My point in steps b to c is to consider two neighboring people in the list at a time and run knows for them to find if they know each other

- sayantan December 19, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

It can be done in O(nlogn). it's a simple quicksort with a given comparator function(knows()). the minimum is solution :)

- Reza January 09, 2013 | Flag Reply


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