+1 adarsh
On Wed, May 2, 2012 at 12:43 PM, adarsh kumar algog...@gmail.com wrote:
Simple, refer this:
http://www.geeksforgeeks.org/archives/2405
On Wed, May 2, 2012 at 1:12 AM, Abhishek Sharma jkabhishe...@gmail.comwrote:
@Bhupendra: your approach is correct but in case the linked lists
@Umer your solution is the obvious one an so good.
Bhupendra solution is much more efficient.
@Abhishek solution is good bu requires more space.
so to conclude
Abhishek sol:
space O(n+m)
time O(n+m)
Bhupendra sol:
space O(1)
time : O(n+m)
Abhishek solution is good it the list are very long and
Simple, refer this:
http://www.geeksforgeeks.org/archives/2405
On Wed, May 2, 2012 at 1:12 AM, Abhishek Sharma jkabhishe...@gmail.comwrote:
@Bhupendra: your approach is correct but in case the linked lists contain
millions of nodes then this might be an overhead.
Another approach could be:
tnx
On 1 מאי, 18:04, Bhupendra Dubey bhupendra@gmail.com wrote:
start from head of both and as soon as one of the list is empty means you
hit null
start counting the remaining number of nodes in the other list till that
gets empty.
Now the number obtained above is the difference in
i dont understan if i look in the pic i attached then the length of
the first list is 5 and the length of the second list is 6.
what should i do now?
if i traverse the long list 5,6 nodes i dont get to the red node.
what am i missing?
On 1 מאי, 18:04, Bhupendra Dubey bhupendra@gmail.com
look at the length before the red node.
3 2 so difference is 1.
Now if pointer in longer list has already moved difference lengths before
pointer in shorter list is started then they will both take equal time to
reach the junction of the list.
On Tue, May 1, 2012 at 9:17 PM, rafi
@Bhupendra: your approach is correct but in case the linked lists contain
millions of nodes then this might be an overhead.
Another approach could be:
- Start with the head of of both the lists.
- Store (Hash) the addresses to which the current nodes are pointing to, in
a hashtable.
- while