Problem · Math

Alternating Parity Permutations

Learn this problem
MediumAtlassian logoAtlassianINTERNFULLTIMEOA

Problem statement

Consider the distinct integers from 1 through n. Count permutations in which every adjacent pair has different parity.

Function

countGoodPermutations(n: int) → long

Examples

Example 1

n = 4return = 8

Choose whether odd or even comes first, then independently order the two odd and two even values.

Constraints

  • 1 <= n <= 11

More Atlassian problems

drafts saved locally
public long countGoodPermutations(int n) {
  // Write your code here.
}
n4
expected8
checking account