Intersection point of two linked lists

getting TLE.

@RULEREMPIRES
Bro i have corrected ya code.


Buddy rather than using this inefficient approach, use two pointer approach instead.
I am giving you the algorithm try to code it!

We call it difference of node counts.

  1. Get count of the nodes in the first list, let count be c1.
  2. Get count of the nodes in the second list, let count be c2.
  3. Get the difference of counts d = abs(c1 – c2).
  4. Now traverse the bigger list from the first node till d nodes so that from here onwards both the lists have equal no of nodes.
  5. Then we can traverse both the lists in parallel till we come across a common node.
    (Note that getting a common node is done by comparing the address of the nodes).

Try it buddy!

Also if ya query is resolved then mark it resolved and rate full!
Happy Coding!