## Amazon Interview Question for Quality Assurance Engineers

Country: United States
Interview Type: In-Person

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

start two pointer from starting point of the list and increase 1st pointer by one and 2nd by two if the point meet on same point than the list is circular list else not.

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

start two pointer from starting point of the list and increase 1st pointer by one and 2nd by two if they pointer meet on same point than the list is circular list else not.

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

{ //Returns true if list is circular, else false
class Node{

int data;
Node next;

return false;
while(temp != NULL){
temp = temp.next;
}
return false;
}
}
}

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

I think this one doesn't work.

Suppose you have a list with an inner cycle like A-> B <--> C than you'll get an infinite loop.

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

``````class Node{
public int data;
public Node next;
Node(int data){
this.data = data;
}
}

public class ListOperations{
return null;
}
Node slow, fast;

do{
slow = slow.next;
if(fast.next != null)
fast = fast.next.next;
else
fast = null;
}while(fast != slow && fast != null);
if(fast == slow){
return fast;
}
else
return null;
}
public static void main(String [] args){
Node a1 = new Node(1);
Node a2 = new Node(2);
Node a3 = new Node(3);
Node a4 = new Node(4);
Node a5 = new Node(5);
Node a6 = new Node(6);
Node a7 = new Node(7);
Node a8 = new Node(8);
Node a9 = new Node(9);
Node a10 = new Node(10);
a9.next = a10;
a8.next = a9;
a7.next = a8;
a6.next = a7;
a5.next = a6;
a10.next = a5;
a4.next = a5;
a3.next = a4;
a2.next = a3;
a1.next = a2;
ListOperations listOps = new ListOperations();
System.out.println(listOps.checkCircular(a1)==null?false:true);
}
}``````

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

As it is not clearly mentioned that either we have to check complete circular or inner circular list. so have to detect any circular relation exist in linkedlist.
We can use HashMap to store each node using this logic.

``````Object obj = new Object;
if(!map.contains(node))
map.put(node,obj);
else
return true;``````

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

class Node
{
Node next;
int info;
Node(int data)
{
info = data;
next = null;
}
Node createList()
{
Node start = new Node(1);
Node mid1 = new Node(2);
Node mid2 = new Node(3);
Node mid3 = new Node(4);
Node end = new Node(5);
start.next=mid1;
mid1.next=mid2;
mid2.next=mid3;
mid3.next=end;
end.next=start;
return start;
}

{
while (temp != null)
{
System.out.println(temp.info);
temp = temp.next;
}
}

void CheckForCircularLL(Node CircularLL)
{
Node slowPtr = CircularLL;
Node fastPtr = CircularLL;
while (slowPtr != null && fastPtr.next!=null)
{
slowPtr = slowPtr.next;
fastPtr = fastPtr.next.next;
if(slowPtr.info == fastPtr.info)
{
System.exit(0);
}
}
}
}

{
public static void main(String[] args)
{
Node ap = new Node(0);
Node circularList = ap.createList();
System.out.println("Check whether Linked List is Circular : ");
System.out.println();
ap.CheckForCircularLL(circularList);

}
}

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

class Node
{
Node next;
int info;
Node(int data)
{
info = data;
next = null;
}
Node createList()
{
Node start = new Node(1);
Node mid1 = new Node(2);
Node mid2 = new Node(3);
Node mid3 = new Node(4);
Node end = new Node(5);
start.next=mid1;
mid1.next=mid2;
mid2.next=mid3;
mid3.next=end;
end.next=start;
return start;
}

{
while (temp != null)
{
System.out.println(temp.info);
temp = temp.next;
}
}

void CheckForCircularLL(Node CircularLL)
{
Node slowPtr = CircularLL;
Node fastPtr = CircularLL;
while (slowPtr != null && fastPtr.next!=null)
{
slowPtr = slowPtr.next;
fastPtr = fastPtr.next.next;
if(slowPtr.info == fastPtr.info)
{
System.exit(0);
}
}
}
}

{
public static void main(String[] args)
{
Node ap = new Node(0);
Node circularList = ap.createList();
System.out.println("Check whether Linked List is Circular : ");
System.out.println();
ap.CheckForCircularLL(circularList);

}
}

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.

### 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.