3577. Count the Number of Computer Unlocking Permutations Medium

@problem@discussion
#Array#Math#Brainteaser#Combinatorics



1/**
2 * [3577] Count the Number of Computer Unlocking Permutations
3 *
4 * You are given an array complexity of length n.
5 * 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].
6 * The password for the computer labeled 0 is already decrypted and serves as the root. All other computers must be unlocked using it or another previously unlocked computer, following this information:
7 * 
8 * 	You can decrypt the password for the computer i using the password for computer j, where j is any integer less than i with a lower complexity. (i.e. j < i and complexity[j] < complexity[i])
9 * 	To decrypt the password for computer i, you must have already unlocked a computer j such that j < i and complexity[j] < complexity[i].
10 * 
11 * Find the number of <span data-keyword="permutation-array">permutations</span> of [0, 1, 2, ..., (n - 1)] that represent a valid order in which the computers can be unlocked, starting from computer 0 as the only initially unlocked one.
12 * Since the answer may be large, return it modulo 10^9 + 7.
13 * Note that the password for the computer with label 0 is decrypted, and not the computer with the first position in the permutation.
14 *  
15 * <strong class="example">Example 1:
16 * <div class="example-block">
17 * Input: <span class="example-io">complexity = [1,2,3]</span>
18 * Output: <span class="example-io">2</span>
19 * Explanation:
20 * The valid permutations are:
21 * 
22 * 	[0, 1, 2]
23 * 	
24 * 		Unlock computer 0 first with root password.
25 * 		Unlock computer 1 with password of computer 0 since complexity[0] < complexity[1].
26 * 		Unlock computer 2 with password of computer 1 since complexity[1] < complexity[2].
27 * 	
28 * 	
29 * 	[0, 2, 1]
30 * 	
31 * 		Unlock computer 0 first with root password.
32 * 		Unlock computer 2 with password of computer 0 since complexity[0] < complexity[2].
33 * 		Unlock computer 1 with password of computer 0 since complexity[0] < complexity[1].
34 * 	
35 * 	
36 * </div>
37 * <strong class="example">Example 2:
38 * <div class="example-block">
39 * Input: <span class="example-io">complexity = [3,3,3,4,4,4]</span>
40 * Output: <span class="example-io">0</span>
41 * Explanation:
42 * There are no possible permutations which can unlock all computers.
43 * </div>
44 *  
45 * Constraints:
46 * 
47 * 	2 <= complexity.length <= 10^5
48 * 	1 <= complexity[i] <= 10^9
49 * 
50 */
51pub struct Solution {}
52
53// problem: https://leetcode.com/problems/count-the-number-of-computer-unlocking-permutations/
54// discuss: https://leetcode.com/problems/count-the-number-of-computer-unlocking-permutations/discuss/?currentPage=1&orderBy=most_votes&query=
55
56// submission codes start here
57
58impl Solution {
59    pub fn count_permutations(complexity: Vec<i32>) -> i32 {
60        0
61    }
62}
63
64// submission codes end
65
66#[cfg(test)]
67mod tests {
68    use super::*;
69
70    #[test]
71    fn test_3577() {
72    }
73}
74

Back
© 2026 bowen.ge All Rights Reserved.