123. Attendance Verdict
A school keeps the attendance of a student for a term as the string log, one character per day: A for absent, L for late and P for present. The student receives a good verdict if two conditions hold together: the log contains fewer than two A days in total, and it never contains three or more L days in a row.
Return true for a good verdict and false otherwise. Scan the log once and keep a count of absences and of the current streak of late days.
Example 1
- Input:
- log = "LPLLP"
- Output:
- true
- Explanation:
There is no absence and the longest streak of late days is two, so the verdict is good.
Example 2
- Input:
- log = "PLLLP"
- Output:
- false
- Explanation:
Three late days in a row break the second rule.
Constraints
1 ≤ log.length ≤ 105
log contains only the characters A, L and P
How this problem is judged
- Answers
- Your answer must match exactly. Numbers compare by value, so 2 and 2.0 are equal.
Expected complexity
- Time
- O(n)
- Space
- O(1)