Count Eight-Neighbor Unlock Patterns
Updated
Problem statement
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) → longExamples
Example 1
rows = 2columns = 2minLength = 2return = 60Every 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 = 6The 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