Count Valid Badge-In Records Over N Days With Absence Limits
Last updated: November 29, 2026
Quick Overview
Each workday an employee's badge record is Present, Late, or Absent. A record is valid if it has fewer than two Absent days in total and never three Late days in a row. Count valid records of length n modulo 1,000,000,007.
0
0
0 solved
Each workday an employee's badge record is Present, Late, or Absent. A record is valid if it has fewer than two Absent days in total and never three Late days in a row. Count valid records of length n modulo 1,000,000,007.
A Google online-assessment hard that rewards a small state machine over (absences so far, trailing late streak). Graders check that n up to 10^5 runs fast and that every transition is accounted for.
What the Interviewer Expects
- Choose states (absences used, current late streak)
- Write transitions for P, L, and A
- Use six rolling counters with a modulus
- Sum all states at the end
- Verify against brute force for small n
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
- Allow up to m absences and no k consecutive lates.
- n is 10^18. How do you compute the answer?
- Count only records with exactly one absence.
- Return how many valid records end with a Late day.
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 the number of strings of length n over {P, L, A} with at most one A and no substring LLL, mod . n = 0 counts the empty record as 1....
High-Level Design
State (a, l): a in {0, 1} absences used, l in {0, 1, 2} trailing Lates. Transitions per day: P resets the streak: (a, l) -> (a, 0). L extends it if allowed: (a, l) -> (a, l + 1) when l < 2. A us...