#3577
Count the Number of Computer Unlocking Permutations
specialist · 760 · lc medium +31 · 59% accepted · 355 likes · top 56%
Description
An integer array complexity of length n gives the password difficulty of n computers labeled 0 through n - 1.
Computer 0 starts already unlocked. To unlock computer i, you need a previously unlocked computer j where j < i and complexity[j] < complexity[i].
Count permutations of [0, 1, ..., n - 1] representing valid unlocking sequences starting from computer 0.
Return the count modulo 109 + 7.
Note: label 0 refers to computer identity, not a position in the permutation.
Code
1
2
3