Student Attendance Record I

You are given a string `s` that records a student's attendance, one character per day: `'A'` absent, `'L'` late, `'P'` present. The student earns an attendance award if they were absent strictly fewer than 2 days in total and were never late on 3 or more consecutive days. Return `true` if the student is eligible, otherwise `false`.

30:00

Student Attendance Record I
easy
Free written solution
Topics
Companies

You are given a string s that records a student's attendance, one character per day: 'A' absent, 'L' late, 'P' present. The student earns an attendance award if they were absent strictly fewer than 2 days in total and were never late on 3 or more consecutive days. Return true if the student is eligible, otherwise false.

Example 1:
Input: {"s":"PPALLP"}
Output: true
Constraints:
  • 1≤s.length≤10001 \leq s.\text{length} \leq 1000

  • s[i] is 'A', 'L' or 'P'.

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"s":"PPALLP"}

attendance: P present, A absent, L late

P

1

P

2

A

3

L

4

L

5

P

6

Walk the record day by day with two counters: total absences (must stay below 2) and the current run of late days (must stay below 3).

absences (total)

0

reaching 2 fails

late days in a row

0

reaching 3 fails; P or A resets

days checked 0 / 6
Variables
VariableValue
absent0
late_streak0
DepthFunction Call
Stack empty
0/7