The logic seems to be correct


but shows error

Hi @vipulch
basically u have to first find the lengths of both lists… if any one is greater than other then move its its pointer by that difference and then compute ans…
refer my code https://ide.codingblocks.com/s/612784

but where is my logic lacking? rather than finding the length of the lists we can just restart the loop when the pointer reaches NULL, its basically doing the same thing isn’t it?

okay okay… so actually ur code is fine… its complexity is just more… just try submitting ur code it will get accepted… dont click on complie and test… directly click on submit code…

It worked, thanks! though will there be a different complexity in the method you told me? wont it be the same?

complexity basically decides ur codes efficiency… like ur code was running in O(N^N) while code i shared runs in linear complexity…

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.