Help with error

prob: https://hack.codingblocks.com/app/contests/2022/1100/problem

sol: https://ide.codingblocks.com/s/408029

I’m getting a seg fault on hackerblocks and on sublime it is not functioning properly , for now I just want to fix that.


Check now .

thanks, at this point I have separated the 2 linked lists, temp is the tail of the linked list which is to be appended at the start of the original one, so when I do temp-> next = head why is it not working.

Send me your updated code. Will look into it.

oh I realize why is not working because I don’t have access to the head of the new linked list form, right?

what you are doing is this

k = 3
        1 2 2 1 8 5 6
              ^     ^
              |     |
            temp1   temp
   head
       1 2 2 1 NULL
       6->1
 

You are doing this
Instead do this

k = 3
1 2 2 1 8 5 6
^     ^ ^   ^
|     | |  (A)
head  | temp 1   
     temp 
First break the linked list temp ->next = NULL {1,2,2,1}
(A) ->next should point to head 
return temp 1 as final linked list will be {8,5,6,1,2,2,1}

Also keep this in mind that k can be greater then n , so before passing the argument do k = k % n

I did the changes but getting seg fault, I don’t understand how k can be greater than n

Check this

That’s a side case which is handled in the code i am attaching in this message [line number 47]

I implemented the logic from your code into my code but I’m getting a seg fault

Line number 18 was causing segmentation fault, the logic i told you is still not correctly implemented by you. You are close. Just dry run your code and you will know where were you wrong.

1 tc is failing

Check now =>

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.