Find the Survivor of Clockwise Elimination. People labeled 1 through n sit clockwise. Start counting at person 1, counting that person as one. Remove the kth counted person, then begin again at the next surviving person clockwise.
### Problem
People labeled 1 through `n` sit clockwise. Start counting at person 1, counting that person as one. Remove the kth counted person, then begin again at the next surviving person clockwise. Repeat until one remains and return the survivor’s label.
```cpp
class Solution {
public:
int findTheWinner(int n, int k);
};
```
### Examples
**Example 1:**
```text
n = 4, k = 2
Output: 1
Explanation: People 2, 4, and 3 leave in that order.
```
**Example 2:**
```text
n = 3, k = 1
Output: 3
Explanation: People 1 and 2 leave before counting reaches the final survivor.
```
### Constraints
- `1 <= k <= n <= 500`.
### Clarifying Questions
Each round includes its starting person in the count. Labels are one-based even if an internal recurrence uses zero-based positions.
```hint Inspect the structure
Which person is counted as one after a removal, and how are surviving labels reported?
```
### Reasoning checkpoints
- Preserve clockwise counting, restarting rules, and one-based output labels.
- Meet the source follow-up of linear time and constant space.
### Optional extensions
The source asks whether this can be solved in linear time and constant space; compare the recurrence with explicit queue simulation.
Overview: Find the Survivor of Clockwise Elimination. People labeled 1 through n sit clockwise. Start counting at person 1, counting that person as one. Remove the kth counted person, then begin again at the next surviving person clockwise.
People labeled 1 through n sit clockwise. Start counting at person 1, counting that person as one. Remove the kth counted person, then begin again at the next surviving person clockwise. Repeat until one remains and return the survivor’s label.
class Solution {
public:
int findTheWinner(int n, int k);
};
Examples
Example 1:
n = 4, k = 2
Output: 1
Explanation: People 2, 4, and 3 leave in that order.
Example 2:
n = 3, k = 1
Output: 3
Explanation: People 1 and 2 leave before counting reaches the final survivor.
Constraints
1 <= k <= n <= 500
.
Clarifying Questions Guidance
Each round includes its starting person in the count. Labels are one-based even if an internal recurrence uses zero-based positions.
Reasoning checkpoints
Preserve clockwise counting, restarting rules, and one-based output labels.
Meet the source follow-up of linear time and constant space.
Optional extensions
The source asks whether this can be solved in linear time and constant space; compare the recurrence with explicit queue simulation.