864. Full Attendance Records
A coach logs every training day of a squad member as one letter: P (present), A (absent) or L (late). A log of length n earns the squad member a full-attendance badge only if it contains fewer than two A letters in total and never three or more consecutive L letters.
Return how many different logs of length n earn the badge, modulo 1_000_000_007 (10^9 + 7). Logs that differ in any position are different.
Example 1
- Input:
- n = 4
- Output:
- 43
- Explanation:
Of the 81 strings over P, A, L of length 4, exactly 43 contain at most one A and no three L in a row.
Example 2
- Input:
- n = 5
- Output:
- 94
- Explanation:
Counting by (absences used, trailing late days) states gives 94 valid records of length 5.
Constraints
- 1 ≤ n ≤ 105
How this problem is judged
- Answers
- Your answer must match exactly. Numbers compare by value, so 2 and 2.0 are equal.
- Time per case
- Python 2,000 msC++ 500 msJava 1,000 msJavaScript 1,000 msTypeScript 1,000 ms
Expected complexity
- Time
- O(n)
- Space
- O(1)