LeetCode 3021: Alice and Bob Playing Flower Game
Problem:
https://leetcode.com/problems/alice-and-bob-playing-flower-game/description
Solution:
Notice that Alice wins if and only if mod , in other words the sum is odd. This is true regardless of the distribution of flowers between the two lanes all that matters in determining the winner is the sum.
The total space of possible pairs contains points.
This space can be visualized as follows for , 5:
We count pairs out of that represent games in which Alice wins.
We also notice a pattern games alternate between Alice and Bob wining.
Another way to think about this problem is to enumerate each possible game in a list.
Game
Game ✅
Game
Game ✅
Game
Since Alice wins on the even-numbered games we can reformulate the problem to ask how many numbers in the range are even?
If is even, the answer is simply , if it is odd, it's and this can be summarized as
Thus, there are games in which Alice wins.