Skip to content
Discussion options

You must be logged in to vote

We are given an array complexity of length n. There are n locked computers labeled 0 to n-1, each with a unique password and a complexity value. The password for computer 0 is already decrypted (root). We can decrypt computer i using computer j if j < i and complexity[j] < complexity[i]. We must have already unlocked computer j.

Approach:

  • Check if computer 0 has the unique minimum complexity in the array
  • If any other computer has complexity ≤ computer 0's complexity, return 0 (no valid permutations exist)
  • Otherwise, computer 0 can unlock all other computers directly or indirectly
  • The remaining n-1 computers can be unlocked in any order, giving (n-1)! permutations
  • Compute (n-1)! modulo 10⁹+7

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@kovatz
Comment options

kovatz Dec 10, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Dec 10, 2025
Maintainer Author

Answer selected by kovatz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants