dheeraj-2000 / dsalgo

Contains Algorithms useful for interview preparation, various practice problems of Arrays, Stacks, queue etc. Contributors are Welcome but, DO NOT MAKE THIS REPO ACT LIKE A SOURCE OF +1.
84 stars 381 forks source link

Josephus problem #384

Open vikashpatel07 opened 2 years ago

vikashpatel07 commented 2 years ago

There are n people standing in a circle waiting to be executed. The counting out begins at some point in the circle and proceeds around the circle in a fixed direction. In each step, a certain number of people are skipped and the next person is executed. The elimination proceeds around the circle (which is becoming smaller and smaller as the executed people are removed), until only the last person remains, who is given freedom. Given the total number of persons n and a number k which indicates that k-1 persons are skipped and kth person is killed in circle. The task is to choose the place in the initial circle so that you are the last one remaining and so survive. For example, if n = 5 and k = 2, then the safe position is 3. Firstly, the person at position 2 is killed, then person at position 4 is killed, then person at position 1 is killed. Finally, the person at position 5 is killed. So the person at position 3 survives. If n = 7 and k = 3, then the safe position is 4. The persons at positions 3, 6, 2, 7, 5, 1 are killed in order, and person at position 4 survives.

Please assign this to me.......

akhilesh59 commented 2 years ago

I would like to contribute for this issue.