Skip to content

Latest commit

 

History

History
35 lines (20 loc) · 1.41 KB

File metadata and controls

35 lines (20 loc) · 1.41 KB

552. Student Attendance Record II

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.

A + A < 2 & L never late for 3 or more consecutive days L or LL is accpetable.

So first, we have a length n, we can have 0 A, 1 A 2 A C(n,0),C(n,1),C(n,2)

And for the rest position we can put A This question is like a combiantion problem.

let me see the std's solution.

all = absent already occured, and last two chars are LL

al = absent already occured, and last char is L

ap = absent already occured, and last char is P .... and so on..

NA means absent not found.

Then it's simple logic that how many options do we have from each each possibility. which can be understood from a dry run!.

because when n = 2 all definitely shall be 0, because we have one absent bu two ll, then it will be inpossible. so on...