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

You can maintain three variable to store the top 3 elements while sweeping the list.

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

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

1. Start one pointer "fp" and iterate through linkedlist until it reaches 3rd node.
2. When "fp" reaches 3rd element, start another pointer "sp" from head node.
3. From now on, advance both pointers"fp" and "sp", node by node until you reach "fp"pointing to NULL.
4. At this time "sp" is pointing to 3rd element from end of the linked list
5. In other words, iterating a pointer to maintain some gap (here 3 in this example)

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

Correct -- Awesome ...Thanks

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

Thx

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

``````/**
*  find kth element
*  o(n)
*/
public void findKthElement(int k)
{
if( head == null ){ //handle k >= length of list
return;
}
while(k > 0){
fast = fast.next;
k--;
}
while(fast != null){
fast = fast.next;
slow = slow.next;
}

System.out.println("kth element value is: " + slow.data );
}``````

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

check if the node->next->next->next is null..if so, then you are at the n-3 rd element.

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

lol no one said that this was the simplest and correct answer lol.

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

I don't think you need 3 temps, 2 are sufficient, one t1 = head->next->next->next, and t2 = head.
Make ++t1, and ++t2, until t1 == NULL.

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

{
while (fast !=null)
{
fast=fast.next.next.next;
current=current.next;
}
return current;
}

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

Hi

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

``````Node* findNthToLast(Node* head, int n)
{
Node* nthToLast = NULL;
int count = 0;
while(temp != NULL)
{
count++;
temp = temp->next
if(count == n)
{
}
else if (count > n)
{
nthToLast = nthToLast ->next;
}

}
if(nthToLast == NULL)
{
cout << "Error: List size is smaller than N"<<endl;
}
return nthToLast;
}``````

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

public void getNthMinusyElement(int n){
System.out.println();
ListNode nthToLast = null;
int count = 0;
while(curr != null)
{
count++;
curr = curr.getNext();
if(count == n)
{
}
else if (count > n)
{
nthToLast = nthToLast.getNext();
System.out.println("data==="+nthToLast.getData());

}

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

}

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.