Ctrl K

Timesheets That Earn the Bonus

Hard
An employee's timesheet for days working days is a string of length days where each character describes one day: - 'P': on time; - 'L': late; - 'A': absent. The attendance bonus is earned when both hold: - there are fewer than two absences ('A') over the whole period; - there are never three or more lates ('L') on consecutive days. How many different timesheets of length days earn the bonus? The answer can be very large, so return it modulo 10⁹ + 7.
Example 1
days=2 → 8

There are 9 two-day timesheets, and only AA misses the bonus because it has two absences.

Example 2
days=3 → 19

Out of 27 timesheets, LLL fails, and so do the seven with two or three absences.

Example 3
days=50 → 100469819

The answer is taken modulo 10⁹ + 7.

Constraints
  • 1 ≤ days ≤ 10⁵
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPattern With Dot and Star HardLongest Balanced Bracket Stretch HardWater Between Walls HardDoes the Text Fit the Pattern HardBiggest Solid Panel Block Hard
loading Python…
Input
days=2
Expected
8

Run checks the first 3 tests in your browser. Submit checks all 14 tests on the server, hidden ones included.