Josephus problem
Practice
3 (2 votes)
Problem
73% Success 748 Attempts 30 Points 5s Time Limit 256MB Memory 1024 KB Max Code
Given the total number of persons n and a number k which indicates that k-1 persons are skipped and a kth person is killed in a circle in a fixed direction. After each operation, the count will start from k+1th person. The task is to choose the safe place in the circle so that when you perform these operations starting from 1st place in the circle, you are the last one remaining and survive.
Example 1:
Input:
n = 3, k = 2
Output: 3
Explanation:
There are 3 persons so skipping 1 person i.e 1st person 2nd person will be killed. Thus the safe position is 3.
Submissions
Please login to view your submissions
Similar Problems
Points:30
7 votes
Tags:
Ad-HocApprovedBasic ProgrammingBrute ForceDynamic ProgrammingMediumOpenSieve
Points:50
2 votes
Tags:
Linear AlgebraHardApprovedMathematicsOpenMatrix Exponentiation
Points:50
6 votes
Tags:
LoopsHardTree
Editorial