/351. Count Valid Android Unlock Patterns

351. Count Valid Android Unlock Patterns

Medium
Dynamic Programming53.8% acceptance

Given two integers min_length and max_length, count the total number of valid unlock patterns on a 3x3 grid that have lengths between min_length and max_length (inclusive). A valid pattern must follow these rules: 1) Each pattern must connect at least min_length keys and at most max_length keys. 2) All keys must be distinct. 3) A move from one key to another is valid only if the line connecting them does not pass through any other key unless that key has already been used in the pattern. Return the total number of valid patterns.

Example 1

Input: 2, 3

Output: 56

Explanation: There are 56 valid patterns of length 2 or 3.

Example 2

Input: 4, 5

Output: 162

Explanation: There are 162 valid patterns of length 4 or 5.

Constraints

  • 1 <= min_length <= max_length <= 9
Python (current runtime)

Case 1

Input: 3, 4

Expected: 104

Case 2

Input: 5, 6

Expected: 260

Case 3

Input: 1, 2

Expected: 25