Can't Draw 100 persons in Circle on a paper! Check This!

interview-questions
Tags: #<Tag:0x00007f18250f9e68>

#1

Can’t Draw 100 persons in Circle on a paper! No worry, check out Josephus Problem on the Internet.
Here, N = 100 and K = 2 (K - 1 number of the persons skipped before killing the next person).
Let’s say the persons are like:
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, …, 98, 99, 100
Now 1 will skip 1 (itself) and kills 2. Then 3 will kill 4 and so on till 99 will kill 100 and gives the sword to 1 (as a circle is there).
Now, 1, 3, 5, 7, …, 97, 99.
After doing the same killing process, we get the sequence as,
1, 5, 9, 13, 17, 21, 25, …, 93, 97, and 1 has the sword.
Again, 1, 9, 17, 25, …89, 97, and 97 has the sword.
After doing this, at last, we will come with 9, 25, 41, 57, 73, 89, and 9 has the sword.
Then, 9, 41, 73, and 9 has the sword —> 9 kills 41 and 73 has the sword and It kills 9 and be the survivor.

Hope you like this explanation!