LeetCode in Kotlin

3360. Stone Removal Game

Easy

Alice and Bob are playing a game where they take turns removing stones from a pile, with Alice going first.

The player who cannot make a move loses the game.

Given a positive integer n, return true if Alice wins the game and false otherwise.

Example 1:

Input: n = 12

Output: true

Explanation:

Example 2:

Input: n = 1

Output: false

Explanation:

Constraints:

Solution

class Solution {
    fun canAliceWin(n: Int): Boolean {
        if (n < 10) {
            return false
        }
        var stonesRemaining = n - 10
        var stonesToBeRemoved = 9
        var i = 1
        while (stonesRemaining >= stonesToBeRemoved) {
            stonesRemaining -= stonesToBeRemoved
            i++
            stonesToBeRemoved--
        }
        return i % 2 != 0
    }
}