Determine whether a student's attendance record is acceptable under simple absence and lateness rules.
Problem
You are given a string representing a student's attendance record over several days.
Each character is one of:
Afor an absenceLfor being latePfor being present
An attendance record is considered acceptable if:
- It contains at most one
A. - It does not contain three or more consecutive
Lcharacters.
Return whether the record is valid.
Notes
You only need to check the whole string once. The task is to validate the sequence against the two rules above.
Input Format
- A single string
sconsisting only of the charactersA,L, andP.
Output Format
- Return
trueif the record is acceptable, otherwise returnfalse.
Constraints
1 <= s.length <= 1000is a reasonable interview-style assumption for this problem.s[i] ∈ { 'A', 'L', 'P' }.- The record is valid only if it has at most one
Aand no substringLLL.
Example 1
Input
s = "PPALLP"
Output
true
Explanation
There is one absence and no three consecutive lates.
Example 2
Input
s = "PPALLL"
Output
false
Explanation
The record contains three consecutive L characters at the end.
Show 1 more example
Example 3
Input
s = "PAAP"
Output
false
Explanation
The record contains two absences.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.