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.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Easy

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
1D dynamic programming
State machine DP
Fibonacci
Counting binary strings
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample Answer
Requirements

Input: integer n >= 0. Output: number of binary strings of length n with no two adjacent 1s, mod 109+710^9+7. 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...


Submit Your Answer
Markdown supported