Test case 1 is showing run error
@Manvik-Arya-4391661007540658 your code is not running where k is a multiple of n. Its working if you do k = k % n in the main() before calling the kappend function. (because then the if part of your function is executed, your else part is not suited for k = 0 and its okay, just do k = k % n no matter what, in the very starting and the code will run fine)