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.

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

Correct Answer.

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

- NaveenG October 06, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Correct -- Awesome ...Thanks

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

Thx

- u.ranjith August 05, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

/**
       *  find kth element
       *  o(n)
       */
       public void findKthElement(int k)
       {
      	if( head == null ){ //handle k >= length of list
      		return;
      	}
      	Node<AnyType> fast = head;
      	Node<AnyType> slow = head;
      	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 );
       }

- Algorithmy October 23, 2014 | Flag
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.

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

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

- anon July 28, 2013 | Flag
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.

- nathaniel September 11, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public Link find(Link first)
{
Link current =first;
Link fast=first;
while (fast !=null)
{
fast=fast.next.next.next;
current=current.next;
}
return current;
}

- m September 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Hi

- a_NEU November 02, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

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

- XnakelX May 20, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

}

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

}

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

class Node:
    def __init__(self, data, next= None):
        self.data=data
        self.next = next

class LinkList:
    def __init__(self):
        self.head = None
    def show_value(self, node_obj):
        if node_obj:
            return f'Data:{node_obj.data}, Next:{node_obj.next}'
    def add_values(self, node_data):
        if not self.head:
            self.head = Node(data=node_data)
            return self.head
        temp = self.head
        while temp.next:
            temp = temp.next
        temp.next = Node(data=node_data)
        return temp.next

    def find_third_last(self):
        if not self.head:
            return None
        elif not self.head.next.next:
            return "Need atleast three elements in list"
        pointer2 = self.head.next.next
        pointer1 = self.head
        while pointer2.next is not None:
            pointer1 = pointer1.next
            pointer2 = pointer2.next
        return self.show_value(pointer1)
x = LinkList()
for i in range(10,90):
    x.add_values(i)
print(x.find_third_last())

- Viraj Gupte October 07, 2022 | 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