[algogeeks] Re: Amazon Interview Q
We should return curr-next in the last statement of ur code On Aug 18, 7:08 am, Dipankar Patro dip10c...@gmail.com wrote: A slight change in above code: make it while(cur cur-next) ^^ other wise the code will crash at last element in a prefect list, with no loop. On 18 August 2011 07:36, Dipankar Patro dip10c...@gmail.com wrote: I have come up with this: - Use only one pointer, NODE *cur - initialize cur to headref - The main loop: while (cur) { if(cur-next-prev != cur) break; cur=cur-next; } return cur; ^^ I think the code is self explanatory. It just uses the fact that at loop, the prev of next to current won't be current. e.g. A-B-C-D-E-F-C Though F is pointing to C, C won't be pointing back to F as the prev of C is pointing to B. Complexity: O(n) On 18 August 2011 04:45, payal gupta gpt.pa...@gmail.com wrote: ys...i guess i misinterpreted..the question.. ma fault... On Thu, Aug 18, 2011 at 4:27 AM, Brijesh Upadhyay brijeshupadhyay...@gmail.com wrote: At the node from where the loop just started.. anyway we could not use that logic , coz it isnt circular linked list! -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/sr4w-kPmnEsJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- ___ Please do not print this e-mail until urgent requirement. Go Green!! Save Papers = Save Trees -- ___ Please do not print this e-mail until urgent requirement. Go Green!! Save Papers = Save Trees -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Amazon Interview Q
we can do that too. But if I return cur then I can myself print cur, cur-next, cur-next-prev. for verification. On 18 August 2011 11:56, Vijay Kansal vijaykans...@gmail.com wrote: We should return curr-next in the last statement of ur code On Aug 18, 7:08 am, Dipankar Patro dip10c...@gmail.com wrote: A slight change in above code: make it while(cur cur-next) ^^ other wise the code will crash at last element in a prefect list, with no loop. On 18 August 2011 07:36, Dipankar Patro dip10c...@gmail.com wrote: I have come up with this: - Use only one pointer, NODE *cur - initialize cur to headref - The main loop: while (cur) { if(cur-next-prev != cur) break; cur=cur-next; } return cur; ^^ I think the code is self explanatory. It just uses the fact that at loop, the prev of next to current won't be current. e.g. A-B-C-D-E-F-C Though F is pointing to C, C won't be pointing back to F as the prev of C is pointing to B. Complexity: O(n) On 18 August 2011 04:45, payal gupta gpt.pa...@gmail.com wrote: ys...i guess i misinterpreted..the question.. ma fault... On Thu, Aug 18, 2011 at 4:27 AM, Brijesh Upadhyay brijeshupadhyay...@gmail.com wrote: At the node from where the loop just started.. anyway we could not use that logic , coz it isnt circular linked list! -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/sr4w-kPmnEsJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- ___ Please do not print this e-mail until urgent requirement. Go Green!! Save Papers = Save Trees -- ___ Please do not print this e-mail until urgent requirement. Go Green!! Save Papers = Save Trees -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- ___ Please do not print this e-mail until urgent requirement. Go Green!! Save Papers = Save Trees -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: Amazon Interview Q
Hi Piyuesh Same Question i Faced Some Times Ago, Have a look at algo/code let me know if any test case missed ? http://shashank7s.blogspot.com/2011/05/wap-to-detect-loop-in-doubly-linked.html if we wants to remove loop from DLL, we can do in the same way we used to do for singly linked list while taking care of test cases. Thanks Shashank Mani Computer Science Birla Institute of Technology Mesra -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/MsPCoJLD2hYJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.