> ## Documentation Index
> Fetch the complete documentation index at: https://leetcode-py.wisl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> leetcode-py is a Python LeetCode practice environment generator with one CLI: lcpy. It is not a service or platform.
> Each problem is a directory under leetcode/ with README.md, solution.py, test_solution.py, helpers.py, and playground.ipynb. lcpy gen creates them from JSON templates bundled with the package.
> Examples are backed by tests; copy them verbatim.

# Student Attendance Record I Python Solution

> Tested Python solution for LeetCode 551 with 20 pytest cases. Generate a practice environment with lcpy.

LeetCode 551, [Easy](/catalog/easy). Topics: [String](/catalog/topics/string). [View on LeetCode](https://leetcode.com/problems/student-attendance-record-i/description/).

Generate this problem as a practice environment: tested reference solution, 20 [parametrized pytest cases](/practice/testing), and a playground notebook:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
lcpy gen -n 551   # by problem number
lcpy gen -s student_attendance_record_i   # by problem name
```

## Problem

You are given a string `s` representing an attendance record for a student 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.

The 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.

Return `true` if the student is eligible for an attendance award, or `false` otherwise.

### Examples

```
Input: s = "PPALLP"
Output: true
Explanation: The student has fewer than 2 absences and was never late 3 or more consecutive days.
```

```
Input: s = "PPALLL"
Output: false
Explanation: The student was late 3 consecutive days in the last 3 days, so is not eligible for the award.
```

### Constraints

* 1 \<= s.length \<= 1000
* s\[i] is either 'A', 'L', or 'P'.

## Solution

Reference implementation from [solution.py on GitHub](https://github.com/wislertt/leetcode-py/blob/main/leetcode/student_attendance_record_i/solution.py), full suite in [test\_solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/student_attendance_record_i/test_solution.py):

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
class Solution:
    # Time: O(n)
    # Space: O(1)
    def check_record(self, s: str) -> bool:
        absent = 0
        late_run = 0
        for c in s:
            if c == "A":
                absent += 1
                if absent >= 2:
                    return False
                late_run = 0
            elif c == "L":
                late_run += 1
                if late_run >= 3:
                    return False
            else:
                late_run = 0
        return True
```

## Complexity

| Time | Space |
| - | - |
| O(n) | O(1) |

## Tags


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.