Even-After-Odd : segmentation fault


why this is giving me seg. fault even though my ans got accepted???
nd what would be space complexity of my code ???
is my code efficient ???
i used 2 stack to store even value and odd .then made two head ,one for even nd one for odd ,afer then i simply connect odd tail to even head.

where do u get segmentation fault ??
i see u get 100% accepted

since u are making extra stack it takes O ( n ) space

& then again reconstructing the linked list
so yes the code is inefficient

u can watch this vide


in this just the pos are checked for odd even u need to check for the value of nodes


check this code with comments for efficient O ( nodes) time and O(1 ) space

1 Like

Thankyou . i got ur point .

1 Like

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.