Code RoomAndroid unlock patterns
HardPrep Room Coding #1360

Android unlock patterns

CodingAlgorithms & data structuresSenior–Staff~35 min

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->3 requires 2 first; 1->9 requires 5 first). Return the total number of distinct valid unlock patterns of length in [m, n]. 1 <= m <= n <= 9.

Implement
number_of_patterns(m: int, n: int) → int
Examples
in[1,1]out9
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 35 min
InputExpectedGot
[1,1]9not run yetsample