Tap here to switch tabs
Problem
Submissions

Problem: Count the Number of Computer Unlocking Permutations

med
30 min
Try to solve the Count the Number of Computer Unlocking Permutations problem.

Statement

You are given an integer array complexity of length n, where complexity[i] represents the security complexity of computer i. There are n computers numbered from 00 to n −1- 1.

Initially, you have access to the root password to unlock computer 00. A remaining computer j can be unlocked if and only if there is at least one already unlocked computer i such that complexity[i] < complexity[j].

An unlocking sequence is a permutation p of all computer indices from 00 to n −1- 1 such that:

  • p[0] =0= 0

  • For every index k from 11 to n −1- 1, there exists some index i with 0≤0 \leq i <k< k such that complexity[p[i]] < complexity[p[k]]

Return the number of valid unlocking permutations. Since the answer may be large, return it modulo 109+710^9 + 7.

Constraints:

  • 2≤2 \leq complexity.length ≤105\leq 10^5

  • 1≤1 \leq complexity[i] ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Count the Number of Computer Unlocking Permutations

med
30 min
Try to solve the Count the Number of Computer Unlocking Permutations problem.

Statement

You are given an integer array complexity of length n, where complexity[i] represents the security complexity of computer i. There are n computers numbered from 00 to n −1- 1.

Initially, you have access to the root password to unlock computer 00. A remaining computer j can be unlocked if and only if there is at least one already unlocked computer i such that complexity[i] < complexity[j].

An unlocking sequence is a permutation p of all computer indices from 00 to n −1- 1 such that:

  • p[0] =0= 0

  • For every index k from 11 to n −1- 1, there exists some index i with 0≤0 \leq i <k< k such that complexity[p[i]] < complexity[p[k]]

Return the number of valid unlocking permutations. Since the answer may be large, return it modulo 109+710^9 + 7.

Constraints:

  • 2≤2 \leq complexity.length ≤105\leq 10^5

  • 1≤1 \leq complexity[i] ≤109\leq 10^9