solve
that takes n
and k
as arguments.n
is 1, return 0 as the base case.solve(n-1, k)
to get the winner's position in a circle with one less friend.k
and taking modulo n
to get the correct position in the current circle.findTheWinner
function calls solve
with n
and k
and adds 1 to the result to convert from 0-indexed to 1-indexed position.