Akamai Interview Question for Quality Assurance Engineers


Country: India
Interview Type: In-Person




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

Use two pointers. Increment one pointer one position at a time and the other pointer two positions at a time. When the fast pointer reaches the end, the slow pointer should be at the middle position.

- Sandy September 04, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Using two pointers is not one pass.

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

Using 2 pointers is considered one pass..you are surely using 2 pointers but traversing the list only once.

- Angie September 04, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I would not consider using two pointers to be one pass. Advancing two pointers through a linked list is the same as traversing it twice.

- eugene.yarovoi September 04, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Even if we consider it , what if number of elements in linked list is even ??

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

Isn't that one pass means one loop?

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

I guess different people may mean different things. But advancing two pointers is similar work to looping twice. You access every node twice, and so I would call that two passes.

- eugene.yarovoi September 05, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

You can do any number of operation on node in a single pass. Doing two operations t->next & t->next->next, is not consider two passes, it is consider as one pass.

- tej November 02, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@tej: We can argue about definitions, but it'll take 2N linked list pointer accesses. That's all I meant.

- eugene.yarovoi November 02, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

The while loops runs only once... and in that both pointers are incremented, so its one pass.

nodeType *slow = head;
nodeType *fast = head;
while(fast != null)
{
fast = fast -> link;
(i%2 == 0)
{
slow = slow -> link;
}
}

This way slow points to middle at the end. When fast reaches null.

- Neo February 26, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

/**
      *  find mid point
      *  2 pointers - one more 2 times faste
      */
      public void findMidPoint()
      {
     	if( head == null ){
     		return;
     	}
     	Node<AnyType> fast = head;
     	Node<AnyType> slow = head;
     	while(true){
     		if( fast == null || fast.next == null ){
     			System.out.println("mid point value is: " + slow.data );
     			break;
     		}
     		
     		fast = fast.next.next; 
     		slow = slow.next;	
     	}
      }

- Algorithmy October 23, 2014 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

If you don't want to use 2 pointers.. you can use array to store all values like

while(! node->next)
{
   a[i++]  = node->deata;
   node = node->next;
   count++;
}
cout << "moddle one is " << a[count/2];

- Hitesh Vaghani September 05, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I don't think this is the best solution for this problem, the reason they mention that size of list is not known is to give you a hint that size is sufficiently large. Copying data into another list doesn't sound optimal to me.

- ravigupt January 20, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Type& findMiddleNode()
{
int check = 0;
nodeType *current;
nodeType *mid;

current = first;
mid = first;

while (current != NULL)
{
current = current->link;
check = (check + 1) % 2;

if (check == 0)
mid = mid->link;
}

return mid->info;
}

- jayram singh September 04, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int middleOfList(node *head)
{
if(head == NULL || head->next == NULL)
return -1;

node *ptr1 = head;
node *ptr2 = head->next;

while( ptr2 && ptr2->next)
{
ptr1 = ptr1->next;
ptr2 = ptr2->next->next;
}
return ptr1->data;
}

- nayak September 04, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

One corner case, which one is the middle one if number of elements is even in linked list ?

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

hahaha... best joke I ve come across in any forums... :D

- Anonymous January 27, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

public void getMiddleElemnet(){
System.out.println();
ListNode curr = head;
ListNode curr1 = head;
while (curr!=null && curr.getNext() !=null) {
curr = curr.getNext().next;
curr1 = curr1.getNext();

}
System.out.println(curr1.getData());
}

- Vipul Agarwal April 08, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 votes

I seriously suggest you google for "what is a linked list". LOL

- Anonymous September 04, 2012 | 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