#552
Student Attendance Record II
expert · 1270 · lc hard +32 · verified · 56.4% accepted · 2,362 likes · top 51%
Description
An attendance record of length n is a string built from three characters:
- 'A': Absent.
- 'L': Late.
- 'P': Present.
A record is award-eligible when both of these hold:
- Total absences are strictly fewer than 2.
- There is no run of 3 or more consecutive late days.
Given n, count all award-eligible records of that length and return the result modulo 109 + 7.
Example 1:
Input: n = 2
Output: 8
Explanation: There are 8 records with length 2 that are eligible for an award:
"PP", "AP", "PA", "LP", "PL", "AL", "LA", "LL"
Only "AA" is not eligible because there are 2 absences (there need to be fewer than 2).
Example 2:
Input: n = 1
Output: 3
Example 3:
Input: n = 10101
Output: 183236316
Code
1
2
3