Interview conceptCoding & Algorithms

Time Windows, Scheduling, And Notifications

Asked of: Software Engineer

Last updated

What's being tested

These problems test interval algorithms, event-driven simulation, and stateful time processing over ordered data. You must normalize time zones and boundary semantics, merge or subtract windows efficiently, process same-timestamp events deterministically, and preserve correctness across recurring schedules and account state changes.

Patterns & templates

  • Sweep line for interval union/difference: sort endpoints, track active counts, and emit transitions in O(n log n) time.

  • Convert recurring weekly times to integer minutes in [0, 10080), apply offsets modulo a week, and explicitly handle wraparound intervals.

  • For allowed-minus-freeze windows, merge overlaps first, subtract freezes with two pointers, then filter by lead time, minimum duration, and result cap.

  • Use a priority queue or k-way merge for notification streams; define deterministic ordering by timestamp, event type, and stable identifier.

  • Model account changes as ordered events with explicit state transitions; renewal, cancellation, and plan-change precedence must be documented.

  • Use a rolling window with a deque or per-key queues; evict timestamps < current - window, maintaining O(n) total work.

  • Separate computation from rendering: calculate eligible notifications first, sort/filter efficiently, then apply templates; avoid repeated scans over large account lists.

Common pitfalls

Pitfall: Treating interval endpoints inconsistently; choose half-open [start, end) semantics so adjacent windows do not create false overlap.

Pitfall: Applying time-zone offsets after filtering; convert candidate intervals to UTC before lead-time comparisons, while preserving duration.

Pitfall: Assuming input order resolves ties; explicitly specify same-time event precedence and stable tie-breakers.

Practice these

The practice cards below cover the canonical variants — solve all of them and time yourself.

Practice questions

Related concepts