title: Production code for finding junction in a linked list
body: <p>I was asked this question in some interview.</p>
  
  <p>I was required to write code for finding junction in a linked list (which is in form of Y with both arms not necessarily equal) for production environment in O(1) space and linear time.<br>
  I came up with this solution (which i had previously seen somewhere) :<pre>
  1. Measure lengths of both lists, let them be l1 and l2 
  2. Move the pointer of larger list by |(l1-l2)|.
  3. Now move together both the pointers, if they point to same location,
  that is the junction.
  </pre>
  Interviewer: How will your code handle ?  </p>
  
  <blockquote> Case 1. The Y-format linked list has loop in the end after the junction.  <br/>  
  Case 2. Either of the input lists is cyclic and they don't merge.  <br/>
  Case 3. The Y-format list has loop in the end before the junction.</blockquote>
  
  <p>In response to case 1, my answer was:<blockquote>I will find the loop in the list using two pointers (one fast and slow), measure the length to the node at which both the pointers meet and then proceed as previous case.</blockquote>
  Whereas, for cases 2 and 3, I was able to figure out no better solution than gracefully exiting when a loop is detected (using the 2-pointer technique).</p>
  
  <p><br/>
  I believe there are better answers to this problem.Please drop down yours :).</p>
  
  <p>Thanks,</p>