Amazon Interview Question for Software Engineer / Developers






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

Use Hare and tortoise alogirthm as circular linked list is nothing but loop in a linked list.

- aravinds86 February 07, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

have two pointers in a list. a and b
b points to two locations ahead of a so every time a->next->next = b.
if there is a loop at any point u ll keep going through the many times depending on the size of the loop and eventually in a circular loop u ll get b->next = a.
return there.. elese it just means it is a big list... gotta better answer?

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

Keep two pointers - One stationary pointer and another moving pointer.
Move the "moving pointer" and traverse the list one by one. At a time both pointers will be equal if it is a cyclic list

- Some one March 17, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This solution will not help if the loop is not at the start of the node.

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

its said circular linked list and not loop in singly linked list.

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

Keep two pointers - One stationary pointer and another moving pointer.
Move the "moving pointer" and traverse the list one by one. At a time both pointers will be equal if it is a cyclic list



above is correct ans

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

void function(node *start)
{
if(start==NULL)
{
cout<<"Empty list"<<endl;
return;
}
if(start==start->next)
{
cout<<"circular"<<endl;
return;
}
else if(start->next==NULL)
{
cout<<"not circular"<<endl;
return;
}
node *ptr=start->next;

while(ptr->next!=NULL && ptr!=start)
ptr=ptr->next;

if(ptr->next==NULL)
{
cout<<"not circular"<<endl;
return;
}
else
cout<<"Circular"<<endl;
}
}

- Manu August 28, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

How about this
1. Go to the last node of that linked list.
2. check if lastNode.Link == null, then it is a singly linked list. Or it is circular.

- pritam83 August 14, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

we can never know about the last node if we dont know that whether it is circular list or not because check condition get changed for normal list while(ptr!=NULL) and for circular its while(ptr==start)..... So ...
ptr=start->next
while(1)
{
if(ptr==null)
{list is not cirular;
exit(0);}
elseif(ptr=start)
{list is circular
exit(0)}
else
{ptr=ptr->next};
}

- ponder December 19, 2010 | 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