Something is wrong in my code

Please check my code and tell me why all test cases are not passed.

it is mentioned in the question that the k can be greater then the n so you have to handle that case as well.
you can handle that by doing taking modulus.