Student Attendance Record I - Problem
Imagine you're a teacher evaluating students for the perfect attendance award at the end of the school year! ๐
You have a student's attendance record represented as a string s, where each character tells you what happened on that day:
- 'A' - Absent (student didn't come to school)
- 'L' - Late (student arrived after the bell)
- 'P' - Present (student was on time)
To win the attendance award, a student must meet both criteria:
- ๐ซ No more than 1 absence - They can miss at most 1 day total
- โฐ Never late 3+ days in a row - No streaks of 3 or more consecutive late days
Return true if the student qualifies for the award, false otherwise.
Example: "PPALLP" โ true (1 absence, max 2 consecutive lates)"PPALLL" โ false (3 consecutive lates = disqualified!)
Input & Output
example_1.py โ Basic Valid Case
$
Input:
s = "PPALLP"
โบ
Output:
true
๐ก Note:
The student has 1 absence (โค 1 allowed) and maximum 2 consecutive lates (< 3 allowed). Both conditions satisfied.
example_2.py โ Too Many Consecutive Lates
$
Input:
s = "PPALLL"
โบ
Output:
false
๐ก Note:
Although only 0 absences, the student has 3 consecutive lates which violates the attendance policy.
example_3.py โ Too Many Absences
$
Input:
s = "ALAPPLA"
โบ
Output:
false
๐ก Note:
The student has 2 absences, which exceeds the maximum allowed (1). The consecutive late condition is satisfied but overall ineligible.
Constraints
- 1 โค s.length โค 1000
- s[i] is either 'A', 'L', or 'P'
- Case sensitive: Only uppercase letters are valid
Visualization
Tap to expand
Understanding the Visualization
1
Start the Review
Begin with clean counters: 0 absences, 0 consecutive lates
2
Daily Assessment
For each day, update your mental notes and check if limits are exceeded
3
Immediate Decision
Stop as soon as you find a violation - no need to continue checking
4
Award Verdict
If you finish without violations, the student gets the award!
Key Takeaway
๐ฏ Key Insight: We can solve both conditions simultaneously in one pass, making immediate decisions without storing historical data!
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code