Gives segmentation fault

question :-https://online.codingblocks.com/app/player/106000/content/150330/4856/code-challenge
code:-https://ide.codingblocks.com/s/354377

please check my code,where it get wrong

hello @Nikhil-Jettley-2567269533523013 the question link is not opening .
but you have doubt in link list k append ?
right ?

hey @Nikhil-Jettley-2567269533523013 i have corrected your code and now it is giving the correct answer .
please try to understand it by doing dry run for it https://ide.codingblocks.com/s/354382
if you still have any confusion in any line please ask here .
Happy Learning !!

sir i understand the complete code,but can’t able to understand line no 44 and 45,why you performed this two operation for obtaining the value to run the while loop.https://ide.codingblocks.com/s/354382

sir it still not works for two or more test cases.

@Nikhil-Jettley-2567269533523013 in line no 44 and 45 we have to handle side cases like what when k is greater than n .
like :
input : 7
1221856
8
output should be : 6122185
in this example as k is greater then n so that why you have to do as k%n because by doing this we are making k as 1 that means we have to append only the last element at the front .
k=n-k
is we are doing so that we can make our pointer to reach at on previous position to the node from which we have to append it to first .

Thank you sir for explaining excellently and in very simple wording, sir but when i submit it not run for one or more test cases.

@Nikhil-Jettley-2567269533523013 please share the code which you are submitting

hey @Nikhil-Jettley-2567269533523013 please try now .


i guess there was one case when k and n are equal and now i have made the changes .
now it should pass test cases .
if you feel that your doubt is cleared please mark this doubt as resolved and please do give good rating .
Happy Learning !!

hello @Nikhil-Jettley-2567269533523013
u have reopend the doubt , i think tushar has already cleared ur doubt very well.
if u still have any doubt then feel to ask here