Student Attendance Record II - Problem
An attendance record for a student can be represented as a string where each character signifies whether the student was absent, late, or present on that day. The record only contains the following three characters:
- 'A': Absent
- 'L': Late
- 'P': Present
Any student is eligible for an attendance award if they meet both of the following criteria:
- The student was absent (
'A') for strictly fewer than 2 days total - The student was never late (
'L') for 3 or more consecutive days
Given an integer n, return the number of possible attendance records of length n that make a student eligible for an attendance award.
The answer may be very large, so return it modulo 109 + 7.
Input & Output
Example 1 — Small Case
$
Input:
n = 2
›
Output:
8
💡 Note:
Valid 2-character strings: PP, PL, PA, LP, LL, LA, AP, AL. Invalid: AA (2 absents), LLL would be invalid if n=3
Example 2 — Minimum Size
$
Input:
n = 1
›
Output:
3
💡 Note:
All single characters are valid: P, L, A (none violate the constraints)
Example 3 — Larger Input
$
Input:
n = 10101
›
Output:
183236316
💡 Note:
Large input demonstrating modular arithmetic is required due to exponential growth
Constraints
- 1 ≤ n ≤ 105
- Answer fits in 32-bit integer after modulo operation
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code