#3021

Alice and Bob Playing Flower Game

specialist · 750 · lc medium +31 · verified · 60.2% accepted · 518 likes · top 59%

Description

Alice and Bob play a turn-based game on a field with two flower lanes. Lane one has x flowers and lane two has y flowers.

Rules:
- Alice moves first.
- Each turn, the current player removes one flower from either lane.
- After a turn, if both lanes are empty, the current player wins.

Given integers n and m, count pairs (x, y) where:
- Alice wins with optimal play.
- 1 <= x <= n and 1 <= y <= m.

Return the count of such pairs.

Example 1:

Input: n = 3, m = 2
Output: 3
Explanation: The following pairs satisfy conditions described in the statement: (1,2), (3,2), (2,1).

Example 2:

Input: n = 1, m = 1
Output: 0
Explanation: No pairs satisfy the conditions described in the statement.

Code

1
2
3