FastPrepAndroid Unlock Pattern Count
Problems/Android Unlock Pattern Count

Android Unlock Pattern Count

Google logoGoogle● HardNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report names counting Android nine-grid unlock patterns. We chose the usual 3x3 numbering, the rule about keys in between, the interface with a minimum and a maximum length, the examples, and the limits, to match the well-known Android Unlock Patterns problem. Our version is about 85% the same as the reported question.

The Android unlock screen has nine keys in a 3x3 grid, numbered:

1 2 3
4 5 6
7 8 9

A 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) → int

Examples

Example 1

minLength = 1maxLength = 1return = 9

Every individual key is a valid length-one pattern.

Example 2

minLength = 1maxLength = 2return = 65

There are 9 length-one patterns and 56 valid length-two patterns.

Example 3

minLength = 4maxLength = 4return = 1624

The 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

Interview reports that mention this question

  • Google PhD New Grad SWE Interview Questions: 1 Experience

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int numberOfUnlockPatterns(int minLength, int maxLength) {
        // write your code here
    }
}
Checking account…