Adobe Interview Question for Software Engineer / Developers






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

If the linked list does not contain a cycle, then this partial function is injective (one-to-one), meaning that no two nodes map to the same successor. Injective functions can indeed be inverted, which is why you can reverse a regular linked list. However, if the list contains a cycle, then there are two nodes with the same successor, so the function is not injective and thus does not have an inverse. So no, you cannot reverse the linked list and expect to get another linked list, if the list has a cycle.

However, if you treat the linked list as a more general graph in which each node can have any number of incoming or outgoing edges, then the inverse does exist. It's just not a linked list anymore.

- Unknown June 15, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Nice Explanation

- Ashupriya July 05, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. use three node pointers to keep the preNode, curNode, nextNode, and change their next pointers.
initially: preNode = NULL; curNode = head; nextNode = head->next;
then update: curNode->next = preNode; preNode = curNode; curNode = nextNode, nextNode = nextNode->next.
of course, be careful to boundary cases such no or only one node in the list

2 and 3, use two nodes with different travel speed, the fast one will meet or over with the slower one when their is loop.

- proboy July 20, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

why do you want the slower one to move? keep it fixed at one place (pointing to a node) so that the faster one can catch it even quicker in case of loop.

- simple February 21, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

To find a Loop in link list is a two runners Problem.

Take two Pointers Like P and Q.

Change both with different speed Like p=p->next; q=q->next->next;
If at any Place they will be equal and It means Loop is there

- Surender Malik July 20, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. Using recursion for reversing a linked list avoids using extra variable.Agreed, call stack will be used but manual manipulations can be avoided.So I feel.

Code:

NODE *head; //pointer to the first node of list

Recur_rev(NODE *p)
{
if(p->next != NULL)
{
Recur_rev(p->next);
p->next->next = p;
}
else
head = p;

}

- Abhishek July 21, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Code has a flaw.. After complete execution of this recurssive function.. The last element's next will be pointing to the 2nd last element (instead of pointing to NULL).. which will create a loop of two elements with last and 2nd last elements in loop..

- Vignesh May 16, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

2. Agreed with Surender and proboy. To find the the starting node from where the loop starts, just find the number steps taken by any of the nodes(P or Q) on their meeting.
Then, start from beginning of list again.Increment first pointer in unit steps and the second with the number calculated above
When both the pointers point to the same node, there you have your starting node.

- Anonymous July 21, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

bool isLoopExist(struct node * root )
{
struct node *p,*q;
if( root == NULL )
return false;
p = root;
q = p->next;
while( q ! = NULL )
{
if( p == q )
return true;
p = p->next;
q = (q->next == NULL ) ? q->next : g->next->next ;
}
return false;
}

- rbc_cc July 21, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

But the last part ..remains how do we know where the loop exists??

- maverick! July 23, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Check for the condition where the next pointer of the current node is equal to the head/root i.e.

if(curNode->next==head)
  //found
else
  curNode = curNode->next;

- darklrd July 30, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

u might not say loop will exsist in begining of list(head node)
there ill be possible loop in list (element 2 and 3 )
we cant check only head...

- kalai July 08, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

1.Take two pointer
2.keep moving first node by one node and second by two node
3.In each step check whether both pointers are same or not after crossing first node.
4.If both pointers are pointing to same node that means loop exists return current node.
5.If not and both pointers reached to null that means... no loop exists...!!

- PKT August 02, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This method is also dependent on Floyd’s Cycle detection algorithm.
1) Detect Loop using Floyd’s Cycle detection algo and get the pointer to a loop node.
2) Count the number of nodes in loop. Let the count be k.
3) Fix one pointer to the head and another to kth node from head.
4) Move both pointers at the same pace, they will meet at loop starting node.
5) Get pointer to the last node of loop and make next of it as NULL.

- sudhanshu pandey August 06, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

start with 2 pointer let t1 nd t2.
move t1 pointer by 1 nd t2 pointer by 2.
if at any time t1==t2 then we have a loop in the list.

for start point take third pointer t3 nd start t3 from start.
t1 nd t2 will be moving in the loop only.
dont change t1 nd increase t2.
move t2 one by one nd chk if t3==t2.
if t2==t1 then increment t3. nd keep chking like this if any time t2==t3 then t3 is the starting of the loop.

- shane August 12, 2011 | 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