Determine blockage and parse HTML tokens
Company: Snapchat
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Quick Answer: This question evaluates computational geometry and graph connectivity for the circular-stones subproblem and parsing plus tree data-structure manipulation for the HTML-like token subproblem, measuring skills in modeling spatial overlap, graph traversal/union operations, hierarchical DOM construction, and dynamic node insertion/deletion.
Constraints
- 0 <= n <= 2000, where n is the number of stones
- 1 <= width <= 10^9
- -10^9 <= xi, yi <= 10^9
- 0 <= ri <= 10^9
- Two stones connect if (xi - xj)^2 + (yi - yj)^2 <= (ri + rj)^2
- A chain blocks the river if it connects y <= 0 to y >= width via overlaps/touches
- Use integer arithmetic (squared distances) to avoid floating-point errors
Hints
- Model stones as nodes in an undirected graph; connect nodes whose discs overlap or touch.
- Add two virtual nodes representing the bottom and top banks; connect stones that touch these banks.
- Use Disjoint Set Union (Union-Find) to efficiently track connectivity.
- Compare squared distances to avoid computing square roots.