Run time error in code

Could you please check my code?

hi @priyamthakuria27 intiialise head1=NULL and head2=NULL for all the test cases.

Doesn’t solve. still says RUNTIME error on all test cases.

@priyamthakuria27 please share your code by saving it on the IDE

@priyamthakuria27 send head by reference in the insert function. Please always test your code for the sample input and match the output for sample output, they are given for a reason.

@Ishitagambhir i did run the code for sample test cases.

Could you check now?

@priyamthakuria27 this latest code seems fine to me…are you getting any problems during submission?

@priyamthakuria27 try to add the condition in the very starting of merge function

if (head1 == NULL) return head2;
if (head2 == NULL) return head1;

It is giving segmentation fault if any one of the linked lists is empty. You are assuming that at least 1 node will be there in both lists

@Ishitagambhir Thank you.

1 Like

@priyamthakuria27 dont forget to mark the doubt as resolved!