sanjithkanagavel
BAN USERSolution:
1.traverse and find the length of both the lists and now traverse biggest list with big_len-small_len and after that traverse both the list by 1 and you will find them meet at one point if they have any intersection.
2.Create a hashtable.traverse the first list and make entry into the hash table and now traverse the second list and find whether the entry has been already made or not.
Arrays :
Random Access.
Excess of data are allocated even when they are not required.
Contigious memory allocation hence fast access to memory(very helpful in cache memory).
Linked List:
Sequential order.
Run time memory creation.
Random location creation of memory .
Arrays :
Random Access.
Excess of data are allocated even when they are not required.
Contigious memory allocation hence fast access to memory(very helpful in cache memory).
Linked List:
Sequential order.
Run time memory creation.
Random location creation of memory .
Solutions :
1.Two pointer Solution (move first pointer to n and then start moving both the pointer till first touches the end and now the second pointer is the nth node from end)
2.Traverse once and check the length of the list and now traverse len-n times from beginning.
3.Use Hashtable <position,data> push everything into the hasttable and pop the len_of_hash-n from the table
4.Push every data into stack and now pop up the value n times and then you will get your node.
Different Solutions :
1.Floyd Cycle
2.Use a hash table and check whether the element exists or not.
3.Add visited nodes and check whether the current node has already visited or not using that list.
If the elements in the list are consecutive like 1,2,3,4,1,5 . then it can be easily solved by XORing. 1^2^3^4^1^5=1.
If they are not consecutive then sort the values and compare its adjacent values using == or XOR.
nothing more than is feasible.
Double recursion is the only way :D
- sanjithkanagavel July 19, 2014