Android unlock patterns

Write codeHard35 minGoogle style

Your task

On a 3x3 Android unlock grid (keys numbered 1-9 row by row), a valid pattern visits between m and n distinct keys in sequence. Moving between two keys is allowed only if the key in the exact middle of the line between them has already been visited (e.g. going 1 to 3 requires 2 first; 1 to 9 requires 5 first). Return the total number of distinct valid unlock patterns of length in [m, n]. 1 <= m <= n <= 9.

Examples

number_of_patterns(m: int, n: int) -> int
Example 1
Inputnumber_of_patterns(1, 1)
Output9