FastPrepCount Eight-Neighbor Unlock Patterns
Problems/Count Eight-Neighbor Unlock Patterns

Count Eight-Neighbor Unlock Patterns

Google logoGoogle● HardFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report asks for the "Number of unlock patterns having length atleast L".

It says moves go to the immediate neighbors in eight directions, with no revisits and no jumping. It does not give grid limits. Here, each grid dimension is at most 4, ordered paths from every start count separately, and a length above the cell count gives zero.

Our version is about 95% the same as the reported question.

A rows by columns grid contains one dot at each cell. A pattern starts at any dot and visits distinct dots. Each move goes to an immediately adjacent cell in one of eight directions: up, down, left, right or a diagonal. A move never jumps over another cell.

Return the number of patterns containing at least minLength dots. The starting dot counts toward the length. Different ordered dot sequences are different patterns, even if they use the same cells. When minLength exceeds the number of dots, return 0.

For this exercise, use the bounded grid sizes below and return the exact count as a 64-bit integer.

Function

countNeighborPatterns(rows: int, columns: int, minLength: int) → long

Examples

Example 1

rows = 2columns = 2minLength = 2return = 60

Every pair of different cells is adjacent. There are 12 length-two, 24 length-three and 24 length-four patterns, totaling 60.

Example 2

rows = 1columns = 3minLength = 2return = 6

The row has four directed adjacent pairs and two length-three patterns. Jumping directly from one end to the other is not allowed.

Constraints

  • 1 <= rows <= 4
  • 1 <= columns <= 4
  • 1 <= minLength <= 17

More Google Onsite Interview questions

  • 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
  • Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Filesystem Entity Total SizeONSITE INTERVIEW · Seen Nov 2026
  • Longest Subarray Within an Absolute-Difference LimitONSITE INTERVIEW · Seen Nov 2026
  • Reach a Destination Through Scheduled FlightsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Maximum Words in Disjoint Grid PathsIndeed · PHONE SCREENIndeed interview questions
  • Count and Score Distinct Hat AssignmentsRoblox · ONSITE INTERVIEWRoblox interview questions
  • Maximum Currency Conversion Along a Simple PathRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
  • Maximize Valid TrainsBNSF Railway · ONSITE INTERVIEWBNSF Railway interview questions
  • Enumerate Right-and-Down Matrix PathsOracle · ONSITE INTERVIEWOracle interview questions
  • Beautiful ArrangementMathWorks · ONSITE INTERVIEWMathWorks interview questions
  • Choose the Next Minesweeper ActionRunloop · PHONE SCREEN
  • Empty ShelfSquarepoint Capital · OASquarepoint Capital interview questions
  • Longest Anchored Song ChainIntuit · OAIntuit interview questions
  • Minimum Moves to Spread Stones Across a GridAmerican Express · OAAmerican Express interview questions

Interview reports that mention this question

  • Google L4 ML Loops and Team Matching: 8 Experiences (Part 2 of 4)

Google interview experiences

  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
  • Google Experienced SWE First Round and Onsite: 1 Experience
  • Google AI Coding Interview and AI OA: 2 Experiences
  • Google SWE Intern Interview Results Timeline: 13 Experiences
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public long countNeighborPatterns(int rows, int columns, int minLength) {
        // Write your code here.
    }
}
Checking account…