Please tell me where did i make a mistake in my code.
Case 1 and 4 didnt pass
Runtime error on case 1 and 4
Hello @ankush.bhardwaj0,
-
Your code is giving the wrong answer for the case when the intersecting node is the first node:
Example:
3
1 2 3
3
1 2 3
Expected Output:
1
Your Output:
2
Reason:
it is skipping a node in every test case.
Solution:
Execute the following statements after the checks
p1 = p1->next;
p2 = p2->next; -
There is a redundancy of code:
Reason:
Because the length of linked lists from p1 and p2 to end of list resp. becomes equal.
Solution:
No need for the if-else statement
I have modified your code, for better understanding:
Hope, this would help.
Give a like, if you are satisfied.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.