Daily Limit on Different Notifications
Updated
Problem statement
Given notifications in the order they are sent and a limit k, 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. The same message may be sent any number of times. Go through the notifications in order. A notification is sent if its message was already sent earlier that day, or if fewer than k different messages have been sent that day so far. Otherwise it is refused.
A refused notification is not sent, so it does not use up the limit. Each new day starts with no messages sent.
Function
shouldSend(messages: String[], days: int[], k: int) → boolean[]Examples
Example 1
messages = ["sale","live","sale","drop","live"]days = [1,1,1,1,2]k = 2return = [true,true,true,false,true]On day 1, "sale" and "live" use up the limit of 2. The second "sale" is a repeat, so it is sent. "drop" would be a third different message, so it is refused. Day 2 starts fresh, so "live" is sent.
Example 2
messages = ["promo","promo","news","news","promo"]days = [3,3,3,4,4]k = 1return = [true,true,false,true,false]With k = 1, day 3 only allows "promo", so "news" is refused. On day 4, "news" comes first and takes the only slot, so "promo" is refused.
Example 3
messages = ["alert","digest","alert","digest"]days = [5,5,5,5]k = 1return = [true,false,true,false]All four notifications are on day 5. "alert" takes the only slot, so every "digest" is refused and every "alert" is sent.
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 <= 105
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
- Count Distinct Underwriting PII ValuesAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions
- Bounded IPv4 FilterAmazon · PHONE SCREEN
- SimpleRDD Multiset IntersectionDatologyAI · PHONE SCREEN
- Vehicle Maintenance Event ReadinessWaymo · PHONE SCREENWaymo interview questions
- Summarize the Latest Event for Each DeviceOneTrust · PHONE SCREEN
- Project JSON Fields into a Target FormatBooking.com · PHONE SCREEN
- Employee Training StatusVanta · PHONE SCREEN
- Select Object by Key ExtremeBridge · PHONE SCREENBridge interview questions
- Group Names by DepartmentMastercard · PHONE SCREENMastercard interview questions
- AI Role: Collection with Add and Remove OperationsApple · PHONE SCREENApple interview questions