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
The total space of possible pairs
This space can be visualized as follows for
1 | 2 | 3 | 4 | 5 | |
|---|---|---|---|---|---|
1 | ✅ | ✅ | |||
2 | ✅ | ✅ | ✅ | ||
3 | ✅ | ✅ |
We count
We also notice a pattern
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
If
Thus, there are