Skip to content

552. Student Attendance Record II #162

Discussion options

You must be logged in to vote

We can use a dynamic programming approach. Given the constraints, especially the high value for n, an efficient solution is required.

Here's a step-by-step solution approach:

Solution Approach

  1. Define the State Variables:
    We use dynamic programming to keep track of the number of valid records based on:

    • Number of absences
    • Number of consecutive late days

    Let:

    • dp[i][0][0] be the number of valid records of length i with 0 absences and no late days.
    • dp[i][0][1] be the number of valid records of length i with 0 absences and 1 late day.
    • dp[i][0][2] be the number of valid records of length i with 0 absences and 2 consecutive late days.
    • dp[i][1][0] be the number of valid records of length i wi…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@mah-shamim
Comment options

mah-shamim Sep 7, 2024
Maintainer Author

@basharul-siddike
Comment options

Answer selected by mah-shamim
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested hard Difficulty
2 participants