← Snapchat Interview Insights

Snapchat·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Snapchat software engineer interview with a graph/Union-Find problem. Pretty standard algorithmic round, one question, and the whole thing hinged on whether you could spot the connected components insight fast enough.

Questions Asked (1)

Q1

Given n stones placed on a 2D grid, a stone can be removed if it shares a row or column with at least one other remaining stone. What is the maximum number of stones you can remove?

Algorithms & Data Structures
Author's notes

The brute force instinct here is a trap you have to talk yourself out of.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as a graph where each stone is an edge connecting its row and column nodes. The maximum number of stones that can be removed equals the total number of stones minus the number of connected components in this graph, because each component must leave at least one stone. Use union-find or DFS to count components efficiently.

Pro tip: Clarify that the answer is n minus the number of connected components, and mention that this is a classic problem (e.g., LeetCode 947). Showing awareness of the graph transformation and its proof demonstrates strong algorithmic maturity.

1. Understand the problem and constraints

Restate the problem: stones can be removed if they share a row or column with another remaining stone. Ask about input size and whether coordinates are bounded.

2. Model as a graph

Treat each row and column as nodes, and each stone as an edge connecting its row and column. This transforms the removal condition into connectivity of edges.

3. Identify the key insight

In each connected component, you can remove all but one stone. Thus, maximum removable stones = total stones - number of connected components.

4. Choose an algorithm

Use union-find (disjoint set union) to efficiently count connected components, or DFS/BFS on the graph. Union-find is often simpler and faster for this problem.

5. Implement and verify

Write code to build the graph, union row and column nodes for each stone, then count unique components. Test with edge cases like no stones, all stones isolated, or all connected.

Key Points to Mention

  • Graph modeling: rows and columns as nodes, stones as edges
  • Connected components and their role in removal
  • Formula: max removable = n - number of components
  • Union-Find (Disjoint Set Union) for efficient component counting
  • Time and space complexity: O(n α(n)) time, O(n) space
  • Edge cases: empty input, all stones isolated, all stones in one component

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