You are viewing a single comment's thread. Return to all comments →
I guess the logic fails if the input is as follows:
1 2 3 4 5
According to given constraint : 1 <= d <=n,
d will not exceed n
Even if there was no constraint, you could just do: k % n, and then apply the same logic.