Count Even-Product Triplets

Combinatorics · Easy · Free problem
Given a list of integers, count how many unordered triplets $(a, b, c)$ -- chosen from distinct positions in the list -- have an even product. **Constraints:** -
\leq n \leq 10^5$ where $n$ is the length of the list - Elements may be positive, negative, or zero - Triplets are unordered combinations (not permutations) **Examples:** Example 1: `nums = [1, 2, 3, 4, 5]` Output: `9` Explanation: Total triplets = $\binom{5}{3} = 10$. The only odd triplet is $\{1, 3, 5\}$. So
0 - 1 = 9$. Example 2: `nums = [1, 3, 5, 7]` Output: `0` Explanation: All elements are odd, so every product is odd. $\binom{4}{3} - \binom{4}{3} = 0$. Example 3: `nums = [2, 4, 6]` Output: `1` Explanation: Only one triplet exists and it contains all even numbers, so product is even.

Open the full interactive solver, hints, and worked solution →