Count Notification Schedules With No Two Back-to-Back Alert Days
Last updated: November 29, 2026
Quick Overview
Over an n-day period each day either sends a digest notification or stays quiet, and the product rule forbids alerts on two consecutive days. Count the valid schedules modulo 1,000,000,007.
0
0
0 solved
Over an n-day period each day either sends a digest notification or stays quiet, and the product rule forbids alerts on two consecutive days. Count the valid schedules modulo 1,000,000,007.
Google interviewers like counting questions that hide a two-state DP; this one comes from notification fatigue rules in apps like Google News. They check that you define states by the last day's choice and that you know the answer is a Fibonacci number.
What the Interviewer Expects
- Define states by whether the last day sent an alert
- Write transitions between the two states
- Give base cases for n = 0 and n = 1
- Keep it O(1) space with modulus
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Generalize to at most k alerts in any run of consecutive days.
- What if at least one alert is required every 3 days?
- n is 10^18. How do you compute the count?
- How many valid schedules have exactly m alerts?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: integer n >= 0. Output: number of binary strings of length n with no two adjacent 1s, mod . n = 0 counts the empty schedule as 1....
High-Level Design
Track two counts after day i: quiet (schedules ending in a quiet day) and alert (ending in an alert). A quiet day can follow anything: quiet' = quiet + alert. An alert can only follow a quiet da...