Run Error in one case

Submission #6092438
The method suggested in the hint also iterates over the list from front, in my algorithm I do it from backwards. Why RE?

@alien
In your iterative solution(last submitted code), you have iterate till while(l1.top()==l2.top()). what if l1 or l2 stack become empty, in that case it’s top doesn’t exit and will give segmentation fault. So change the condition of while loop to while(!l1.empty() && !l2.empty() && l1.top()==l2.top())

All testcase will pass

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.