Switch It Up
Description:
Note: The problem is identical to raulbc777's kata Shuffle It Up but with slightly more challenging tests.
Problem Statement
Assume we have a list of n
elements: [1, 2, 3, ..., n]
.
The task is to compute the number of ways to rearrange the elements such that no element remains in its initial position.
As input we are given the number of elements N, a positive integer. Since the answer grows rather quickly as n
increases, we compute the answer modulo 1,000,000,007
.
Example
Input: n = 3 => [1, 2, 3]
There are two ways of rearranging the elements of [1, 2, 3]
such that no element is in its original position:
[2, 3, 1], [3, 1, 2] => return 2
See the sample tests for more examples.
Input/Output
Input: a positive integer 1 <= n <= 8,000,000
.
Output: also an integer, as specified in the problem statement above.
The input will always be an integer in the given range, no need to handle bad input.
Similar Kata:
Stats:
Created | Feb 4, 2021 |
Warriors Trained | 25 |
Total Skips | 0 |
Total Code Submissions | 497 |
Total Times Completed | 14 |
Python Completions | 14 |
C++ Completions | 0 |
Total Stars | 1 |
% of votes with a positive feedback rating | 50% of 10 |
Total "Very Satisfied" Votes | 3 |
Total "Somewhat Satisfied" Votes | 4 |
Total "Not Satisfied" Votes | 3 |
Total Rank Assessments | 10 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 4 kyu |
Lowest Assessed Rank | 8 kyu |