Solve Three Coding Problems
Company: Snapchat
Role: Software Engineer
Category: Coding & Algorithms
Interview Round: Onsite
The interview included three coding problems:
1. **Streaming top-k class.** Design a class for an integer stream with a fixed parameter `k`. It should support `add(x)` to ingest a new value and `getTopK()` to return the `k` largest values seen so far in descending order. If fewer than `k` values have appeared, return all of them. Aim for efficient incremental updates.
2. **Maximum safe delay in a burning grid.** You are given an `m x n` grid containing empty cells, walls, and initial fire sources. Fire spreads every minute to the four neighboring non-wall cells. A person starts at the top-left cell and wants to reach the bottom-right cell. Before moving, the person may wait for `t` minutes at the start, then moves one step per minute through non-wall cells. The person may never enter a cell after the fire has arrived there; arriving at the destination at the same minute as the fire is allowed. Return the maximum `t` that still allows escape, return `-1` if escape is impossible even with no waiting, and return `1000000000` if escape is possible for arbitrarily large `t`.
3. **Reachability in a rectangle with circular blockers.** You are given a rectangle with corners `(0, 0)` and `(X, Y)`, along with several closed circles inside or touching the rectangle. Determine whether there exists a continuous path from `(0, 0)` to `(X, Y)` that stays within the rectangle and never touches or enters any circle. The path may move in any direction.
Quick Answer: This set of problems evaluates competencies in streaming data handling and incremental aggregation, time-dependent grid traversal and reachability under dynamic hazards, and planar path existence with geometric obstacles, touching on data structures, graph algorithms, and computational geometry within the Coding & Algorithms domain.