Problem · Math
Alternating Parity Permutations
Learn this problemProblem statement
Consider the distinct integers from 1 through n. Count permutations in which every adjacent pair has different parity.
Function
countGoodPermutations(n: int) → longExamples
Example 1
n = 4return = 8Choose whether odd or even comes first, then independently order the two odd and two even values.
Constraints
1 <= n <= 11