24. Josephus Problem
โ GFG solution to the Josephus Problem: find the survivor's position in a circular elimination game using iterative DP, recursion, and mathematical optimization. ๐
๐งฉ Problem Description
๐ Examples
Example 1
Input: n = 5, k = 2
Output: 3
Explanation: Firstly, the person at position 2 is killed, then the person at position 4 is killed,
then the person at position 1 is killed. Finally, the person at position 5 is killed.
So the person at position 3 survives.Example 2
Input: n = 7, k = 3
Output: 4
Explanation: The elimination order is 3 โ 6 โ 2 โ 7 โ 5 โ 1, and the person at position 4 survives.๐ Constraints
โ
My Approach
Iterative DP Solution
๐ Time and Auxiliary Space Complexity
โ๏ธ Code (C)
๐งโ๐ป Code (C++)
โ Code (Java)
๐ Code (Python)
๐ง Contribution and Support
๐Visitor Count
Last updated