Android Unlock Pattern Count
Problem statement
The Android unlock screen has nine keys in a 3x3 grid, numbered:
1 2 3
4 5 6
7 8 9A pattern visits distinct keys. A move that passes directly through another key is allowed only if that intermediate key was already visited. For example, 1→3 requires 2, 1→9 requires 5, and 3→7 requires 5. All other moves are allowed.
Return the number of valid patterns whose length is between minLength and maxLength, inclusive.
Function
numberOfUnlockPatterns(minLength: int, maxLength: int) → intExamples
Example 1
minLength = 1maxLength = 1return = 9Every individual key is a valid length-one pattern.
Example 2
minLength = 1maxLength = 2return = 65There are 9 length-one patterns and 56 valid length-two patterns.
Example 3
minLength = 4maxLength = 4return = 1624The standard Android movement rules permit 1624 patterns of exactly four keys.
Constraints
1 <= minLength <= maxLength <= 9.