← Google Interview Insights

Google·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Google SWE interview with a grid-based combinatorics problem. The question looked like a puzzle at first glance but turned into a pretty involved backtracking exercise once you started thinking about the constraints.

Questions Asked (1)

Q1

Given a 3x3 keypad lock screen with 9 keys, count the number of valid unlock patterns of length k where m <= k <= n. A valid pattern uses distinct keys connected in sequence, and if a line between two consecutive keys passes through another key, that key must have already been visited.

Algorithms & Data Structures
Author's notes

The 'passing through' constraint is where I stumbled.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the keypad as a graph where edges represent valid moves, including special 'skip' edges that require an intermediate key to be visited first. Use DFS with backtracking to explore all valid patterns of length between m and n, leveraging symmetry to reduce redundant computations.

Pro tip: Precompute the skip conditions and use symmetry: patterns starting from 1, 3, 7, 9 are equivalent, as are 2, 4, 6, 8, and 5 is unique. This reduces the search space by a factor of 8 and shows optimization awareness.

1. Model the keypad as a graph

Represent each key as a node and define valid moves between keys. For moves that pass over an intermediate key, store the required intermediate key.

2. Precompute skip conditions

Create a 2D array 'skip' where skip[i][j] is the key that must be visited before moving from i to j, or 0 if no intermediate key is required.

3. Use DFS with backtracking

Starting from each key, recursively explore all valid next keys that are unvisited and whose skip condition (if any) is satisfied. Track the current pattern length.

4. Count patterns within length bounds

At each recursion step, if the current length is between m and n, increment the count. Continue until length n.

5. Optimize with symmetry

Compute patterns for one key from each symmetry group (corner, edge, center) and multiply by the group size to avoid redundant work.

Key Points to Mention

  • Graph representation of the keypad with nodes and edges
  • Skip conditions for moves that pass over an intermediate key
  • Depth-first search with backtracking to explore all valid patterns
  • Symmetry reduction to optimize the solution
  • Time complexity analysis: O(9 * 8! ) worst-case, but symmetry reduces it
  • Handling of edge cases: m=1, n=9, and patterns of length 1

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.