Created
August 27, 2025 18:56
-
-
Save SuryaPratapK/49c80622193147771661dd5cc5f67ccb to your computer and use it in GitHub Desktop.
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
| class Solution { | |
| #define ll long long | |
| public: | |
| long long flowerGame(int n, int m) { | |
| ll count = 0; | |
| //Case-1: Odd in N and Even in M | |
| int odds_in_n = (n+1)/2; | |
| int even_in_m = m/2; | |
| count += (1LL * odds_in_n * even_in_m); | |
| //Case-2: Even in M and Odd in N | |
| int even_in_n = n/2; | |
| int odds_in_m = (m+1)/2; | |
| count += (1LL * even_in_n * odds_in_m); | |
| return count; | |
| } | |
| }; | |
| /* | |
| //JAVA | |
| class Solution { | |
| public long flowerGame(int n, int m) { | |
| long oddsInN = (n + 1L) / 2L; | |
| long evenInM = m / 2L; | |
| long count = oddsInN * evenInM; | |
| long evenInN = n / 2L; | |
| long oddsInM = (m + 1L) / 2L; | |
| count += evenInN * oddsInM; | |
| return count; | |
| } | |
| } | |
| #Python | |
| class Solution: | |
| def flowerGame(self, n: int, m: int) -> int: | |
| odds_in_n = (n + 1) // 2 | |
| even_in_m = m // 2 | |
| count = odds_in_n * even_in_m | |
| even_in_n = n // 2 | |
| odds_in_m = (m + 1) // 2 | |
| count += even_in_n * odds_in_m | |
| return count | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment