There are n friends arranged in a circle, numbered from 1 to n. Starting from friend 1, you repeatedly count k friends in a circular manner. The friend at the k-th count is removed from the circle. After each removal, the counting resumes from the next friend in clockwise direction.
This process continues until only one friend remains.
Your task is to return the number assigned to the last remaining friend.
Input: n = 4, k = 3
Output: 1
Explanation:
Order of removal: 3 → 2 → 4 Only friend 1 remains.
Input: n = 7, k = 2
Output: 7
Explanation:
Friends are removed in the order: 2, 4, 6, 1, 5, 3 → Winner is 7
Accepted:
Submission: