Answer: MongoDB OA Question 2024 July | Intervals | on-campus

Answer · Posted Jun 2026

Solution: Insert Interval — Three Phase Linear Scan Approach We make a single linear pass through the existing intervals, handling three distinct phases: Phase 1 — No Overlap (Before): While the current interval ends before newInterval starts, add it directly to the result. Phase 2 — Overlap (Merge): While the current interval starts before or at newInterval's end, merge by expanding newInterval's boundaries to include both. Phase 3 — No Overlap (After): Add the merged newInterval to the result, then ...

The full answer & interview discussion are available to premium members.

Log in Create a free account