Implement the permutationsCountDistinct method that counts distinct permutations of the given values.

The input array nums contains size distinct values.

Your task is to return how many different permutations can be created using all values from the array. A permutation is an ordering of all elements.

For example, [1,2,3] has 6 permutations because the three values can be arranged in 3 × 2 × 1 ways.

Example 1

Input
nums (int[]) = [1,2,3]
size (int) = 3
Returns (int) 6

Example 2

Input
nums (int[]) = [1]
size (int) = 1
Returns (int) 1

Example 3

Input
nums (int[]) = [1,2]
size (int) = 2
Returns (int) 2

For distinct values, the number of permutations is the factorial of the array size.

There are size choices for the first position, then size - 1 choices for the second position, and so on until only one value remains.

Multiply all numbers from 1 to size to get the total permutation count.

Pseudocode:

function permutationsCountDistinct(nums, size):
    result = 1
    for i from 2 to size:
        result = result * i
    return result
Ready to test your solutionRun Code checks your solution against the test cases.Shift + Enter to run

Notifications

Updates are enabled for this browser.

Receive new tutorials, articles and learning resources. You can turn updates off anytime.

Test browser code

Use this code in admin to send a test notification to this browser.