Design a Balloon Festival Simulator
Company: Optiver
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Online Assessment
Overview: This question evaluates proficiency in data structures, event-driven simulation, numerical aggregation of spatially varying fields, and time-based state tracking for mutable entities.
Constraints
- 1 ≤ len(yourBalloonNames) < 2^20
- Operations are intended to be given in non-decreasing timestamp order; if an operation has timestamp < previous processed timestamp, it must be treated as invalid with no effect
- For this problem, altitudes are integers in meters
- 0 < altitude < 2^15 (i.e., 1..32767) for both balloons and wind sources
- 0 ≤ windSpeed < 2^5 (i.e., 0..31)
- Unstable balloons regain stability after 300 seconds (inclusive) continuously in wind ≤ 15 m/s
Examples
Input: (["Alpha","Bravo"], [("BalloonAscended", 0, "Alpha", 1000), ("BalloonAscended", 0, "Bravo", 500), ("InspectBalloons", 10)])
Expected Output: [True, True, ["Alpha", "Bravo"]]
Explanation: No competitors exist; both balloons are stable and airborne, so both are returned sorted.
Input: (["A","B"], [("BalloonAscended", 0, "A", 1000), ("BalloonAscended", 0, "Rival", 1200), ("InspectBalloons", 1), ("BalloonAscended", 2, "B", 1500), ("InspectBalloons", 3)])
Expected Output: [True, True, [], True, ["B"]]
Explanation: At t=1 the highest stable competitor is at 1200 so A(1000) doesn't qualify. After B ascends to 1500, B qualifies at t=3.
Hints
- Track when an unstable balloon enters a safe-wind condition and schedule the earliest time it could become stable again (e.g., with a min-heap).
- To find the highest stable competitor efficiently, consider a heap with lazy deletion (store versions and discard stale entries).