Skip to content

Instantly share code, notes, and snippets.

@tatsuyax25
Created December 10, 2025 21:35
Show Gist options
  • Select an option

  • Save tatsuyax25/be8289b57b8df7e4b69e1ad3fa98940c to your computer and use it in GitHub Desktop.

Select an option

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
/**
* @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