Daily Notification Limit with Cooldown
Updated
Problem statement
Given notifications in the order they are sent, a daily limit k and a cooldown length cooldown, return a boolean array answer where answer[i] is true if notification i is sent and false if it is refused. Notification i carries the message messages[i] and is sent on day days[i].
On any day, at most k different messages may be sent, and the same message may be sent any number of times. When a notification is refused because its day already has k different messages, its message starts a cooldown. If that refusal happens on day d, the message is refused on every day up to and including day d + cooldown.
Go through the notifications in order and decide each one with these steps:
- If its message was already sent earlier that day, it is sent.
- Otherwise, if its message is in a cooldown, it is refused. This refusal does not start a new cooldown.
- Otherwise, if fewer than
kdifferent messages have been sent that day so far, it is sent. - Otherwise, it is refused and its message starts a cooldown.
A refused notification is not sent, so it does not use up the limit. Each new day starts with no messages sent. Cooldowns belong to one message and do not affect other messages.
Function
shouldSendWithCooldown(messages: String[], days: int[], k: int, cooldown: int) → boolean[]Examples
Example 1
messages = ["sale","live","drop","drop","live","drop"]days = [1,1,1,2,2,4]k = 2cooldown = 2return = [true,true,false,false,true,true]Day 1 is full after "sale" and "live", so "drop" is refused and cools down on days 2 and 3. On day 2, "drop" is refused even though the day has room, while "live" is sent. On day 4 the cooldown is over.
Example 2
messages = ["news","promo","promo","promo","promo"]days = [1,1,2,3,4]k = 1cooldown = 2return = [true,false,false,false,true]"promo" is refused on day 1 by the limit, so it cools down on days 2 and 3. The refusals during the cooldown do not restart it, so "promo" is sent on day 4.
Example 3
messages = ["sale","live","sale","drop","drop"]days = [1,1,1,1,2]k = 2cooldown = 0return = [true,true,true,false,true]With cooldown = 0, a refusal only lasts for the rest of its day. "drop" is refused on day 1 by the limit and sent on day 2.
Constraints
1 <= messages.length <= 105days.length == messages.length1 <= messages[i].length <= 20messages[i]consists of lowercase English letters.1 <= days[i] <= 109daysis sorted in non-decreasing order.1 <= k <= 1050 <= cooldown <= 106
More WhatNot Phone Screen questions
- Adjacent Pair and Run RemovalPHONE SCREEN · Seen Nov 2026
- Merge Sorted Squares of Two ArraysPHONE SCREEN · Seen Nov 2026
- User Journey PathsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Knight Dialer SequencesPHONE SCREEN · Seen Oct 2026
- Reachable Exits in an Obstacle GridPHONE SCREEN · Seen Oct 2026
- Palindrome with One DeletionPHONE SCREEN · Seen Oct 2026
- Search a 2D MatrixPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Attraction Route Without Reusing TrailsPHONE SCREEN · Seen Sep 2026
- Earliest Car for Each PassengerPHONE SCREEN · Seen Sep 2026
- Minimum Stores for a Shopping ListPHONE SCREEN · Seen Sep 2026
Similar questions at other companies
- Logger Rate Limiter with Every-Arrival HistoryGoogle · PHONE SCREENGoogle interview questions
- Propagating Fraud DetectorAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions
- Order and Batch Open-Close LifecycleHudson River Trading · PHONE SCREENHudson River Trading interview questions
- Pins Violation Log QueriesPinterest · PHONE SCREENPinterest interview questions
- Resource Reconciler: Plan and Apply CreatesPerplexity AI · PHONE SCREENPerplexity AI interview questions
- Realized Gains from a Real-Estate Transaction StreamKikoff · PHONE SCREENKikoff interview questions
- Process On-Call Routing OperationsOpenAI · PHONE SCREENOpenAI interview questions
- Batched Key Fetch CallbacksAnrok · PHONE SCREEN
- Stateful Paginated Fetch NLyft · PHONE SCREENLyft interview questions
- Count Active Employee Access GrantsIBM · PHONE SCREENIBM interview questions