Given a non-negative integer n, the total number of wheels, return the number of distinct combinations of 4-wheeler vehicles (4 wheels each) and 2-wheeler vehicles (2 wheels each) that together use exactly n wheels.
A combination is defined by its count of 4-wheelers and its count of 2-wheelers. Order does not matter. Both vehicle types use an even number of wheels, so an odd n has no valid combination.
Function Signature
def count_combinations(n: int) -> int:
Rules
-
A combination is a pair
(a, b)
of non-negative integers with
4 * a + 2 * b == n
, where
a
is the number of 4-wheelers and
b
is the number of 2-wheelers.
-
Two combinations are the same only when both counts match.
-
For
n = 0
the answer is 1: the combination with zero vehicles of each type.
Constraints
Examples
Input: n = 8
Output: 3
The valid combinations (4-wheelers, 2-wheelers) are (0, 4), (1, 2) and (2, 0).
Input: n = 7
Output: 0
n is odd, and any mix of vehicles that each have an even number of wheels has an even total.
Input: n = 6
Output: 2
The valid combinations are (0, 3) and (1, 1). Two 4-wheelers would already need 8 wheels.