An efficient algorithm for a sample counting game

351 Views Asked by At

N people sitting around a table playing a game. The game is like this, for a given number k, each time they will count up until somebody reaches number k. Every time the person that reaches number k will leave the desk and the person next to him starts counting again from 1. Given N and k as inputs, suggest an algorithm to find the winner in an efficient way (Every body can count up just by 1)

1

There are 1 best solutions below

0
On

It's the Josephus problem. It's well discussed here:

http://www.geeksforgeeks.org/josephus-problem-set-1-a-on-solution/