Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Find the Winner of the Circular Game

XPChallenge Points: 20
levelLevel: Medium

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.

Example 1:

Input: n = 4, k = 3

Output: 1

Explanation:

Order of removal: 3 → 2 → 4 Only friend 1 remains.

Example 2:

Input: n = 7, k = 2

Output: 7

Explanation:

Friends are removed in the order: 2, 4, 6, 1, 5, 3 → Winner is 7

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result