← Snapchat Interview Insights

Snapchat·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jul 2026

Summary

Snapchat software engineer interview with two fairly distinct coding problems. One was a geometry/graph problem and the other was a tree-building exercise with a follow-up on mutations. Nothing too wild but the DOM question had more depth than I expected.

Questions Asked (2)

Q1

You're given a set of 2D circles representing stones in a river. Determine whether the stones collectively block the full width of the river. You can define your own input format.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The 'define your own input format' part threw me a little, felt like a trick but it's probably just them being flexible.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model this as a graph connectivity problem where stones 'block' the river if a connected chain of overlapping or touching circles spans from one bank to the other. Represent each circle as a node, add edges between circles that overlap or touch, then use Union-Find or BFS/DFS to check if any component connects the top bank to the bottom bank. This cleanly separates the geometric overlap detection from the connectivity logic.

Pro tip: Proactively define your input format and coordinate system before coding — for example, 'river flows along the x-axis, width spans y=0 to y=W, each stone is (cx, cy, r)' — this signals strong problem-framing skills and avoids ambiguity that interviewers often use to trip candidates up.

1. Define Input & Problem Constraints

Explicitly state your chosen input format (e.g., list of tuples (cx, cy, r)) and clarify the river model — river width W, banks at y=0 and y=W, stones block if they touch or overlap each other and reach both banks. Ask about edge cases like a single stone spanning the full width.

2. Model as a Graph

Treat each stone as a node and add a virtual 'top bank' node and 'bottom bank' node. Two stones are connected if the distance between their centers is less than or equal to the sum of their radii; a stone connects to a bank if it touches or crosses that bank's boundary.

3. Detect Overlaps Geometrically

For each pair of circles, compute the Euclidean distance between centers and compare it to r1 + r2 to determine adjacency. Also check if cy - r <= 0 (touches top bank) or cy + r >= W (touches bottom bank) for bank connections.

4. Run Connectivity Algorithm

Apply Union-Find (for O(α(n)) per union/find) or BFS/DFS starting from all stones touching the top bank, then check if any reachable stone also touches the bottom bank. Return true if such a path exists.

5. Analyze Complexity & Trade-offs

Discuss the O(n²) pairwise overlap check as the bottleneck and mention that spatial indexing (e.g., a grid or R-tree) could reduce this to O(n log n) for large inputs. Acknowledge that Union-Find is preferable over BFS here for incremental updates.

Key Points to Mention

  • Circle overlap condition: distance(c1, c2) <= r1 + r2, using squared distances to avoid costly sqrt when possible
  • Virtual source/sink nodes representing the two river banks to simplify connectivity check
  • Union-Find data structure with path compression and union by rank for efficient dynamic connectivity
  • O(n²) naive complexity for pairwise checks and how spatial data structures (R-tree, grid hashing) can optimize it
  • Edge cases: single stone spanning full width, stones entirely outside the river, circles tangent (touching) vs. overlapping
  • Trade-off between BFS/DFS (simpler to implement) vs. Union-Find (better for dynamic/streaming stone additions)

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

Q2

Given a sequence of HTML-like tokens (for example: open paragraph, raw text 'ABC', close paragraph), parse them and build a DOM tree, then print it. Follow-up: add support for inserting and deleting nodes.

Algorithms & Data StructuresSystem Design
Author's notes

Started with a stack-based approach which felt pretty natural for matching open/close tags.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the token types and expected output format, then design a stack-based parser that builds the DOM tree in a single pass. For the follow-up, extend the node structure to support parent pointers and implement insert/delete operations with proper tree updates.

Pro tip: Mention that you would use a sentinel root node to simplify edge cases like inserting before the first child or deleting the root, and discuss how to handle malformed input gracefully.

1. Clarify requirements and edge cases

Ask about token format, whether tags can be self-closing, how to handle mismatched tags, and what the printed output should look like. Confirm if the follow-up operations need to maintain any specific order.

2. Design the data structures

Define a Node class with tag name, children list, and parent pointer. Use a stack to keep track of the current open element during parsing.

3. Implement the parser

Iterate through tokens: on open tag, create a node, append to current parent, and push onto stack; on text, append to current node; on close tag, pop from stack. Handle errors like unexpected close tags.

4. Implement tree printing

Use depth-first traversal with indentation to print the tree structure, showing tag names and text content clearly.

5. Extend for insert and delete

For insert, create a new node and splice it into the parent's children list at the given index, updating parent pointers. For delete, remove the node from its parent's children and optionally recursively free its subtree.

Key Points to Mention

  • Use a stack to track the current open element during parsing, ensuring O(n) time complexity.
  • Maintain parent pointers in each node to enable efficient insert and delete operations.
  • Handle edge cases: empty input, mismatched tags, inserting at index 0 or at the end, deleting the root node.
  • For printing, use recursion or an explicit stack with depth tracking to produce readable indented output.
  • Discuss time and space complexity: parsing is O(n), insert/delete are O(1) if index is known, otherwise O(k) to find the node.
  • Consider using a sentinel root node to simplify operations that involve the root or first child.

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