Josephus Problem Statement
Consider 'N' individuals standing in a circle, numbered consecutively from 1 to N, in a clockwise direction. Initially, the person at position 1 starts counting and will skip K-1 persons (including themselves), eliminating the Kth person. The counting resumes from the next person, repeatedly skipping K-1 persons and eliminating the Kth one, until only one person remains.
Your task is to determine the position of this last surviving person with respect to the original numbering.
Example:
Input:
T = 1
N = 5, K = 2
Output:
3
Explanation:
In the circle numbered from 1 to 5, every 2nd person is removed until only one remains. Thus, position 3 is the last person standing.
Constraints:
1 <= T <= 50
1 <= N, K <= 104
- Time Limit: 1 sec
This question is about finding the position of the last person surviving in a circle of N people, where each person kills the Kth person in a clockwise direction.
Implement a function that takes the nu...read more
Top Texas Instruments Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
Reviews
Interviews
Salaries
Users/Month