← Snapchat Interview Insights

Snapchat·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Snapchat SWE interview with a classic water jug problem that sounds deceptively simple but has a lot of depth to it. They wanted both a BFS/DFS solution and the math-based gcd approach, plus full complexity analysis and edge case handling.

Questions Asked (1)

Q1

Given two jugs with capacities x and y liters and an unlimited water source, can you measure exactly z liters? You can fill, empty, or pour between jugs. Implement a solution using both a graph-search approach (BFS/DFS over states) and a number-theoretic approach (using gcd), handle edge cases like z == 0, z > x + y, and x or y being 0, and analyze time and space complexity.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

I started with BFS because it felt safer.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem and edge cases, then explain the number-theoretic condition (z must be a multiple of gcd(x,y) and within bounds). Next, describe the BFS/DFS state-space search, emphasizing state representation and transitions. Finally, compare both approaches in terms of complexity and practical trade-offs.

Pro tip: Demonstrate that you can derive the gcd condition from the BFS state transitions, showing deep understanding. Also, mention that BFS finds the shortest sequence of operations, which is often desirable in real-world scenarios.

1. Clarify problem and edge cases

Restate the problem and explicitly handle edge cases: z=0 (always possible), z > x+y (impossible), x=0 or y=0 (only possible if z equals the non-zero jug or 0).

2. Number-theoretic solution

Explain that z is measurable iff z <= x+y and z is a multiple of gcd(x,y). Provide the formula and justify it using Bézout's identity.

3. Graph-search solution

Model states as (a,b) where a and b are current amounts. Use BFS (or DFS) to explore all reachable states via fill, empty, and pour operations. Check if any state has a=z or b=z.

4. Complexity analysis

For BFS: O(x*y) time and space, as there are at most (x+1)*(y+1) states. For gcd: O(log(min(x,y))) time, O(1) space.

5. Compare and conclude

Highlight that the gcd approach is optimal for feasibility, while BFS is needed to find the actual sequence of operations. Discuss trade-offs and when to use each.

Key Points to Mention

  • Edge cases: z=0, z > x+y, x=0 or y=0
  • Number-theoretic condition: z must be a multiple of gcd(x,y) and z <= x+y
  • BFS state representation and transitions (fill, empty, pour)
  • Time and space complexity: O(x*y) for BFS, O(log(min(x,y))) for gcd
  • BFS finds shortest sequence of operations, useful for practical applications
  • Proof of gcd condition using Bézout's identity

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