/**
* Problem: LeetCode 3360 - Stone Removal Game
* Difficulty: Easy
* Language: Java
* Author: CodeByTushu
*/
class Solution {
public boolean canAliceWin(int n) {
int remove = 10;
boolean aliceTurn = true;
while (n >= remove) {
n -= remove;
remove--;
aliceTurn = !aliceTurn;
}
// Jis player ki turn hai aur wo move nahi kar sakta, wo haar gaya.
// Agar ab Bob ki turn hai, matlab Bob haara, Alice jeeti.
return !aliceTurn;
}
}
"""
Problem: LeetCode 3360 - Stone Removal Game
Difficulty: Easy
Language: Python 3
Author: CodeByTushu
"""
class Solution:
def canAliceWin(self, n: int) -> bool:
remove = 10
alice_turn = True
while n >= remove:
n -= remove
remove -= 1
alice_turn = not alice_turn
# Agar ab Bob ki turn hai aur wo move nahi kar sakta, toh Alice jeet gayi
return not alice_turn
/**
* Problem: LeetCode 3360 - Stone Removal Game
* Difficulty: Easy
* Language: C++
* Author: CodeByTushu
*/
class Solution {
public:
bool canAliceWin(int n) {
int remove = 10;
bool aliceTurn = true;
while (n >= remove) {
n -= remove;
remove--;
aliceTurn = !aliceTurn;
}
// Agar Bob ki turn aayi aur wo stones nahi utha paya, toh Alice jeet gayi
return !aliceTurn;
}
};
/**
* Problem: LeetCode 3360 - Stone Removal Game
* Difficulty: Easy
* Language: JavaScript
* Author: CodeByTushu
*/
/**
* @param {number} n
* @return {boolean}
*/
var canAliceWin = function(n) {
let remove = 10;
let aliceTurn = true;
while (n >= remove) {
n -= remove;
remove--;
aliceTurn = !aliceTurn;
}
// Agar Bob ki baari me stones kam pad gaye, toh Alice jeet gayi
return !aliceTurn;
};
TIME COMPLEXITY
O(1)
SPACE COMPLEXITY
O(1)
TOPICS
Data Structure
Game Theory
Math
Prefix Sum
Simulation