Run time error and wrong answer

only one test case shows correct answer
my code is https://ide.codingblocks.com/s/124707
plz tell what is my mistake …

@ejazsaifi70
Your code fails for testcases when k is greater than n. As it is clearly specified in the problem statement "K can be greater than N. " , you need to cover this case as well.

Input :
7
1 2 3 4 5 6 7
10

Expected Output :
5 6 7 1 2 3 4

Your Output :
( Runtime Error )

Try taking the modulo of k with n.
k = k % n;

( Note that your value of n becomes zero after your loop so you might need to save the original value of n in some other variable and use that for modulo).

Also do not forget to cover one corner case when k is a multiple of n and k%n becomes 0. In such a case , do none of your operations and directly your print your original list and that’s it.

1 Like