Created
December 10, 2025 21:35
-
-
Save tatsuyax25/be8289b57b8df7e4b69e1ad3fa98940c to your computer and use it in GitHub Desktop.
You are given an array complexity of length n. There are n locked computers in a room with labels from 0 to n - 1, each with its own unique password. The password of the computer i has a complexity complexity[i]. The password for the computer label
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @param {number[]} complexity | |
| * @return {number} | |
| */ | |
| var countPermutations = function(complexity) { | |
| const n = complexity.length; | |
| const MOD = 1_000_000_007; // Large prime modulus for preventing overflow | |
| // Check validity: all elements after the first must be strictly greater | |
| for (let i = 1; i < n; i++) { | |
| if (complexity[i] <= complexity[0]) { | |
| return 0; // Invalid case | |
| } | |
| } | |
| // Compute factorial of (n-1) modulo MOD | |
| let result = 1; | |
| for (let i = n - 1; i >= 1; i--) { | |
| result = (result * i) % MOD; | |
| } | |
| return result; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment