← Snapchat Interview Insights

Snapchat·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Snapchat SWE interview with a BFS/graph traversal problem dressed up as a lock puzzle. The unit testing requirement caught me a little off guard since most coding rounds skip that entirely.

Questions Asked (1)

Q1

You have a 4-digit combination lock starting at '0000'. Each move rotates one digit up or down by 1 with wraparound. Given a target combination and a list of forbidden states you cannot pass through, find the minimum number of moves to reach the target, or return -1 if it's impossible. Then write unit tests covering: target is '0000', forbidden list includes '0000', unreachable targets, duplicate forbidden entries, and large forbidden sets.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

Classic BFS problem at its core but the forbidden states plus wraparound tripped me up at first.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the lock states as nodes in a graph where edges connect states differing by one digit rotation, then use BFS to find the shortest path from '0000' to the target while avoiding forbidden states. After explaining the algorithm, outline unit tests that cover edge cases like target being the start, forbidden start, unreachable targets, duplicate forbidden entries, and large forbidden sets.

Pro tip: Mention that you can optimize BFS by using a bidirectional search or A* with a heuristic like the sum of minimum rotations per digit, but only if the interviewer shows interest in optimization. Also, emphasize the importance of validating input and handling edge cases early in the code.

1. Clarify problem and constraints

Confirm that each move changes one digit by ±1 with wraparound (0↔9), forbidden states cannot be visited, and the target may be forbidden. Ask about input size and performance expectations.

2. Choose algorithm and data structures

Use BFS because each move has uniform cost and we need the shortest path. Represent states as strings or integers, use a queue for BFS, and a set for forbidden states for O(1) lookups.

3. Implement BFS with forbidden checks

Start from '0000', if it's forbidden return -1. For each state, generate neighbors by rotating each digit up and down, skip if forbidden or visited, and stop when target is reached. Return distance or -1 if queue exhausts.

4. Design comprehensive unit tests

Write tests for: target is '0000' (should return 0), forbidden includes '0000' (return -1), unreachable target (e.g., all neighbors forbidden), duplicate forbidden entries (should not affect result), and large forbidden sets (e.g., 1000 states) to test performance and correctness.

5. Analyze complexity and trade-offs

Discuss time and space complexity: O(10^4) states, each with 8 neighbors, so O(1) effectively. Mention potential optimizations like bidirectional BFS or A* if needed, and trade-offs between pre-processing forbidden set vs. checking on the fly.

Key Points to Mention

  • BFS guarantees shortest path in unweighted graph
  • State representation: string vs integer for efficiency
  • Handling wraparound correctly (0-1=9, 9+1=0)
  • Using a set for forbidden states for O(1) lookup
  • Edge cases: start forbidden, target forbidden, start equals target
  • Unit test coverage: duplicates, large sets, unreachable

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