Expedia Interview Question for Software Engineer in Tests


Country: India
Interview Type: Phone Interview




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

if loop is there in linked list which is sorted and you want to remove it then,
just check if any node whose next node value is less than current node value, if it is true then point the next pointer of current node to null.

- sjain May 21, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 votes

I think it is pretty obvious what to do no?

- aka May 21, 2013 | Flag
Comment hidden because of low score. Click to expand.
-2
of 2 votes

void fixNode(node *head) {
  if (head == nul) {
    return null;
  }
  if (head->next == null) {
    return null;
  }
  node *temp = head;
  while (temp->next!=null) {
    if (temp->value < temp->next->value) {
	  temp->next = null;
	  return;
	}
	temp = temp->next;
  }

- sjain May 21, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Your logic would fail, if the list has duplicates.

1->3->5->8->8->8->8->9

1->3->5->8->8->8->8->
^< -|

- mahendruajay June 16, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Can you elaborate how it will fail.

- sjain June 16, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Yours will fail in case of 1-> 2->3 -> 3->3 -> (back to the 1st 3). dead loop.

- huiyong September 20, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 2 votes

void fixNode(node *head) {
  if (head == nul) {
    return null;
  }
  if (head->next == null) {
    return null;
  }
  node *temp = head;
  while (temp->next!=null) {
    if (temp->value > temp->next->value) {
	  temp->next = null;
	  return;
	}
	temp = temp->next;
  }

some minor change

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

The condition in the above code should be :

if(tmp->data <= tmp->next->data)
   tmp=tmp->next;
 else
  {
     tmp->next=NULL;
     return;
  }

since the list is sorted. Of course, it is still valid if you consider the list is sorted in a descending order :)

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

Since there are only two functions + and * , we need to take care of precedence of * first:

char[] arr = {'4','*','5','+','6','*','2','+','5'};
            NodeS<int> stInt = new NodeS<int>();
            int result = 0;
            for (int i = 0; i < arr.Length; i++)
            {
                if (arr[i] >= 48 && arr[i] <= 57)
                {
                    stInt.Push(arr[i] - '0');
                }
                else if(arr[i] == '*')
                {
                    i++;
                    if (arr[i] >= 48 && arr[i] <= 57)
                    {
                        int f = stInt.Pop() * (arr[i] - '0');
                        stInt.Push(f);
                    }
                }
            }
            while (!stInt.Empty())
            {
                result += stInt.Pop();
            }
            Console.WriteLine(result);

- Shwetha August 21, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Please ignore above, its solution for a different question

- shwetha August 21, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void FixFaultyNodesInSortedLinkedList()
        {
            //Prepare the mock list
            var head = new SingleLinkedList<int>() { Value = 1 };
            var cur = head;
            for (int i = 0; i < 5; i++)
            {
                cur.Next = new SingleLinkedList<int> { Value = i + 2 };
                cur = cur.Next;
            }

            cur.Next = head;
            //***************************************************

            if (head == null || head.Next == null)
                return; //return head;

            cur = head;
            while (cur.Next != null)
            {
                if (cur.Value > cur.Next.Value)
                    cur.Next = null; //fix by setting the next value null. ignore the rest of list for now.
                else
                    cur = cur.Next;
            }

            Console.WriteLine("Print head to tail.");
        }

- Nagesh Agastya April 02, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public void FixedCircularList()
{
lnode p;
p=root;
while (p.link != null)
{
if(p.link!=null)
{
if (p.link.data < p.data )
{
p.link=null;
break;
}
}
p=p.link;
}

}

- CodeJam July 13, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Logic is that in a sorted array, if loop occurs the last element will point somewhere in the midddle and we dont know what is the last number. So keep checking current value < next value. if this fails then make current-> next as null. This is the last element of the list.

- bhavi February 22, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 3 vote

void fixNode(node *head) {
  if (head == nul) {
    return null;
  }
  if (head->next == null) {
    return null;
  }
  node *temp = head;
  while (temp->next!=null) {
    if (temp->value < temp->next->value) {
	  temp->next = null;
	  return;
	}
	temp = temp->next;
  }
}

- sjain May 21, 2013 | 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