package leetcode;

/**
 * https://leetcode.com/problems/find-the-winner-of-the-circular-game/
 */
public class Problem1823 {
    public int findTheWinner(int n, int k) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1823 prob = new Problem1823();
        System.out.println(prob.findTheWinner(5, 2)); // 3
        System.out.println(prob.findTheWinner(6, 5)); // 1
    }
}

package leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * https://leetcode.com/problems/find-the-winner-of-the-circular-game/
 */
public class Problem1823 {
    public int findTheWinner(int n, int k) {
        List<Integer> list = new ArrayList<>();
        for (int i = 1; i <= n; i++) {
            list.add(i);
        }
        int i = 0;
        while (list.size() > 1) {
            i = (i + k - 1) % list.size();
            list.remove(i);
        }
        return list.get(0);
    }
}

Solve problem 1823