Created
August 29, 2025 17:05
-
-
Save tatsuyax25/294500f45e03aec43f11b934c1465835 to your computer and use it in GitHub Desktop.
Alice and Bob are playing a turn-based game on a field, with two lanes of flowers between them. There are x flowers in the first lane between Alice and Bob, and y flowers in the second lane between them. The game proceeds as follows: Alice takes th
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {number} n | |
* @param {number} m | |
* @return {number} | |
*/ | |
var flowerGame = function(n, m) { | |
// Count how many odd numbers are in [1, n] | |
const oddX = Math.floor(n / 2) + (n % 2); // e.g., 1, 3, 5... | |
const evenX = Math.floor(n / 2); // e.g., 2, 4, 6... | |
// count how many odd numbers are in [1, m] | |
const oddY = Math.floor(m / 2) + (m % 2); | |
const evenY = Math.floor(m / 2); | |
// Valid pairs are: | |
// - odd x with even y | |
// - even x with odd y | |
const validPairs = (oddX * evenY) + (evenX * oddY); | |
return validPairs; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment