Amazon Interview Question for Software Engineer / Developers






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

hash the second list.
O(n)

- Y March 19, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Just got a way in linear time with O(1) space complexity.
1. use two pointers scan the two list and get the size of each. say m, n (suppose m>n)
2. use the same two pointers point to the heads again and move the one in the longer list m-n steps.
3. move both of the two pointers step by step, compare their address in each step till find the same one.

- Anonymous March 19, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

right!!! but it is O(n) not O(1)

- clrs March 22, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Op says linear running time with O(1) space complexity. Linear running time means O(n)!

- Anonymous April 18, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

good solution.
based on this one, how about we use to pointers go to the end of each list, then start backwards from the end of the list. this way u don't need to count in the first pass and u dont need to travel the initial n-m steps.

- Anonymous May 05, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can plz explain in detail

- Man March 26, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Its o(n) coz we traverse the entire list !!

- explanator April 12, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Its o(n) coz we traverse the entire list !!

- explanator April 12, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

o(n) time complexity question :)

sruct node *Intersection(struct node *l1,sruct node *l2)
{
int n=0,m=0;
struct node *temp1,*temp2;

if(l1==NULL || l2==NULL)
return NULL:
temp1=l1;
while(temp1)
{
n++;
temp1=temp1->next;
}
while(temp2)
{
m++;
temp2=temp2->next;
}
temp1=l1;
temp2=l2;
if(n>m)
{
temp1=l1;
n=n-m;
while(n)
{
temp=temp->next;
n--;
}
}
else
{
m=m-n;
temp2=l2;
while(m)
{
temp2=temp2->next;
m=m-1;
}}
while(temp1!=temp2)
{
temp1=temp1->next;
temp2=temp2->next;
}
return temp1;}

- Anonymous July 15, 2011 | 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