DevPath

← All problems

Count Permutations

Easy backtracking · math

Description

Return the number of permutations of n distinct elements.

Constraints

0 <= n <= 12

Examples

Input: n = 4

Output: 24

Hints (1)
  • n factorial.

Solutions

Factorial. · Time O(n) · Space O(1)

func countPermutations(n int) int {
    result := 1
    for i := 2; i <= n; i++ {
        result *= i
    }
    return result
}

Create a free account to submit solutions, track progress and save problems.

Create account