File size: 1,842 Bytes
3c88a0f
 
 
 
1
2
3
4
5
{"type": "session", "harness": "opencode", "id": "cp-10057", "name": "LeetCode 0552: Student Attendance Record Ii"}
{"type": "message", "message": {"role": "system", "content": "You are an expert LeetCode problem solver. You solve problems efficiently with clean code."}}
{"type": "message", "message": {"role": "user", "content": "Problem: Student Attendance Record II (Difficulty: Hard)\nTags: Dynamic Programming\n\nAn 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:\nAny student is eligible for an attendance award if they meet both of the following criteria:\nGiven 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.\n\nExample 1:\nInput: n = 2\nOutput: 8\nExplanation: There are 8 records with length 2 that are eligible for an award:\n\"PP\", \"AP\", \"PA\", \"LP\", \"PL\", \"AL\", \"LA\", \"LL\"\nOnly \"AA\" is not eligible because there are 2 absences (there need to be fewer than 2).\n\nExample 2:\nInput: n = 1\nOutput: 3\n\nExample 3:\nInput: n = 10101\nOutput: 183236316\n\nConstraints:\n- 1 <= n <= 10^5"}}
{"type": "message", "message": {"role": "assistant", "content": "# Time:  O(n)\n# Space: O(1)\n\nclass Solution(object):\n    def checkRecord(self, n):\n        \"\"\"\n        :type n: int\n        :rtype: int\n        \"\"\"\n        M = 1000000007\n        a0l0, a0l1, a0l2, a1l0, a1l1, a1l2 = 1, 0, 0, 0, 0, 0\n        for i in range(n+1):\n            a0l2, a0l1, a0l0 = a0l1, a0l0, (a0l0 + a0l1 + a0l2) % M\n            a1l2, a1l1, a1l0 = a1l1, a1l0, (a0l0 + a1l0 + a1l1 + a1l2) % M\n        return a1l0\n\n"}}