mediumArrayBit ManipulationBitmaskDynamic Programming 0 views

Special Permutations

You are given a 0-indexed integer array nums containing n distinct positive integers.

You are given a 0-indexed integer array nums containing n distinct positive integers. A permutation of nums is called special if:

Return the total number of special permutations. As the answer could be large, return it modulo 10^9 + 7.

Special Permutations diagram

Example 1

Input: nums = [2,3,6]

Output: 2

Explanation: [3,6,2] and [2,6,3] are the two special permutations of nums.

Example 2

Input: nums = [1,4,3]

Output: 2

Explanation: [3,1,4] and [4,1,3] are the two special permutations of nums.

Constraints

  • 2 <= nums.length <= 14
  • 1 <= nums[i] <= 10^9

Hints

Companies

No companies reported yet.

Discussion

Sign in to join the discussion.

Loading discussion...

Test results

No test cases yet.