FrontendInterviews.dev

Loading problem…

52. Notification Scheduler with Cooldown Periods

Medium•
Acceptance: 72.73%
•
🔓3/3 Pro unlocks today

You're building a notification system for a social media app. Users can receive different types of notifications (like "like", "comment", "follow", etc.), but to avoid overwhelming users, you need to enforce a cooldown period between notifications of the same type.

Given an array of notification types (each represented by a letter from A to Z) and a cooldown period n, determine the minimum number of time slots needed to schedule all notifications. Each time slot can either:

  • Send one notification, or
  • Be idle (waiting for cooldown to expire)

Constraint: There must be at least n time slots between two notifications of the same type.

Requirements

1. Basic Functionality

  • Accept an array of notification types (strings) and a cooldown period n
  • Return the minimum number of time slots required to schedule all notifications
  • Enforce cooldown period between same-type notifications

Example Usage

Constraints

  • 1 <= notifications.length <= 10^4
  • Each notification type is a single uppercase letter (A-Z)
  • 0 <= cooldown <= 100
  • You can schedule notifications in any order
  • Idle slots can be inserted anywhere to satisfy cooldown requirements