bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 552. Student Attendance Record II

552. Student Attendance Record II

Leetcode Solutions

Approach # Dynamic Programming with Constant Space

  1. Initialize six variables to represent the states: P, L, LL, A, AL, ALL, where P is the count of strings ending with 'P', L with 'L', LL with two 'L's, A with 'A', AL with 'A' and 'L', and ALL with 'A' and two 'L's.
  2. Set initial values: P = 1, L = 1, LL = 0, A = 1, AL = 0, ALL = 0.
  3. Iterate from 2 to n (inclusive), updating the counts for each state based on the previous values.
  4. At each iteration, calculate the new counts for P, L, LL, A, AL, and ALL using the state transition rules.
  5. After the loop, sum up P, L, LL, A, AL, and ALL to get the total number of valid attendance records.
  6. Return the total count modulo 10^9 + 7.
UML Thumbnail

Approach # Using Recursive Formulae

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...