Expedia Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




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

Take two pointers initialise second pointer after moving first pointer n positions so when first pointer will be at last position second pointer will be at nth last position

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

traverse linked list once to find the length of the LL.

then move along the LL, length - n - 1 times to reach the nth last node.

- manishi.singh March 01, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think this should work, not tested though:

node *findLastNth(node *head, int n){
    node *temp = head;
    while(temp != NULL && n--) temp = temp->next;
    
    if(temp == NULL) return NULL;
    
    while(temp){
        temp = temp->next;
        head = head->next;
    }
    return head;
}

- HauntedGhost March 05, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote
{{{ //if list is having odd no. of nodes then code is: n* lastnode(n* hptr) { n * slow,*fast; slow=fast=hptr; while(fast->next!=NULL) { slow=slow->next; fast=fast->next->fast; } return fast; } //if list is having even no. of nodes then code is: n* lastnode(n* hptr) { n * slow,*fast; slow=fast=hptr; while(fast->next->next!=NULL) { slow=slow->next; fast=fast->next->fast; } return fast->next; } //this is O(n) solution with only one traversal using two pointer that are moving at different speed - Vaibhav March 11, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

n* lastnode(n* hptr)
{
	n * slow,*fast;
	slow=fast=hptr;
while(fast->next->next!=NULL)
	{
	slow=slow->next;
	fast=fast->next->fast;
	}
	return fast->next;
}
//for even no. of nodes in the list

- Vaibhav March 11, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

//if list is having odd no. of nodes then code is: n* lastnode(n* hptr) { n * slow,*fast; slow=fast=hptr; while(fast->next!=NULL) { slow=slow->next; fast=fast->next->fast; } return fast;

- Vaibhav March 11, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <iostream>
#include <stdlib.h>
#include "List.h"
#include "Node.h"

using namespace std;

int main()
{
    int k = 0;
    int input = 0;
    int element = 0;
    int listSize = rand() % 80;
    List myList;
    cout << endl;
    for(int i = 0; i < listSize; i++){
        input = rand() % 80;
        myList.addNode(input);
    }
    cout << "To find the kth last element in the list, type the value of k: ";
    cin >> k;
    Node *ptr1 = myList.head;
    int counter = 1;
    while(counter != k){
        ptr1 = ptr1->getNext();
        counter++;
    }
    Node *ptr2 = myList.head;
    while(ptr1->getNext() != NULL){
        ptr1 = ptr1->getNext();
        ptr2 = ptr2->getNext();
    }
    element = ptr2->getData();

    cout << "The " << k << "th last element in the list: ";
    myList.printList();
    cout << "is " << element;
}

- Anonymous August 28, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

class Node {

                int data;
                Node next;

                public Node(int data) {
                        this.data = data;
                        this.next = null;
                }
        }
        
	// Time Complexity O(n)
        Node getElement(Node head, int n) {
                
                Node first = head, second = head;
                
                int count = 0;
                while(null != first && count < n) {
                        first = first.next;
                        count++;
                }
                
                if(count != n) {
                        return first;
                }
                
                while(null != first) {
                        first = first.next;
                        second = second.next;
                }
                
                return second;
        }

- Kapil July 13, 2017 | 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