Skip to content

Practice Student Attendance Record II

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#552
LeetCode Problem

Student Attendance Record II

Problem Statement

Count length-n attendance strings formed from A (absent), L (late) and P (present). A record qualifies only when it contains fewer than two A characters in total and never contains three consecutive L characters. Return the count modulo 10^9 + 7.

Source: Student Attendance Record II on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 2
Output
8

# Example 2

Input
n = 1
Output
3

# Example 3

Input
n = 10101
Output
183236316

Constraints

1 <= n <= 10^5

Related LeetCode Problems

Practice more problems similar to Student Attendance Record II.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.