Student Attendance Record I - 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.
Input & Output
Example 1 — Basic Valid Case
$
Input:
s = "PPALLP"
›
Output:
true
💡 Note:
The student has 1 absence (< 2) and at most 2 consecutive lates (< 3), so they are eligible for the award.
Example 2 — Too Many Absences
$
Input:
s = "PPALLL"
›
Output:
false
💡 Note:
The student has 3 consecutive lates, which violates the attendance policy.
Example 3 — Multiple Absences
$
Input:
s = "ALPPLA"
›
Output:
false
💡 Note:
The student has 2 absences, which is not strictly fewer than 2, so they are not eligible.
Constraints
- 1 ≤ s.length ≤ 1000
- s[i] is either 'A', 'L', or 'P'
Visualization
Tap to expand
Understanding the Visualization
1
Input
Attendance string with A (absent), L (late), P (present)
2
Check Criteria
Count absences < 2 and no 3+ consecutive lates
3
Award Decision
Return true if both conditions are satisfied
Key Takeaway
🎯 Key Insight: Track two simple counters while scanning the string once
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code