Android Unlock Pattern Count
Updated
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.
More Google Onsite Interview questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Maximum Currency Conversion Along a Simple PathRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- Word Ladder II: All Shortest TransformationsPeopleStrong · ONSITE INTERVIEWPeopleStrong interview questions
- Word Ladder IIBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Park Train Cars by PreferenceMercor · ONSITE INTERVIEWMercor interview questions
- Visit Desired Attractions Without Reusing a TrailDuolingo · PHONE SCREENDuolingo interview questions
- Attraction Route Without Reusing TrailsWhatNot · PHONE SCREENWhatNot interview questions
- Enumerate Directed Paths and CyclesByteDance · PHONE SCREENByteDance interview questions
- Longest Anchored Song ChainIntuit · OAIntuit interview questions
- Three-Color an Undirected GraphSnowflake · PHONE SCREENSnowflake interview questions
- Graph M-ColoringAdobe · OAAdobe interview questions