Off-by-one on range boundaries
Wrong move: Loop endpoints miss first/last candidate.
Usually fails on: Fails on minimal arrays and exact-boundary answers.
Fix: Re-derive loops from inclusive/exclusive ranges before coding.
Build confidence with an intuition-first walkthrough focused on core interview patterns fundamentals.
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:
'A') for strictly fewer than 2 days total.'L') for 3 or more consecutive days.Return true if the student is eligible for an attendance award, or false otherwise.
Example 1:
Input: s = "PPALLP" Output: true Explanation: The student has fewer than 2 absences and was never late 3 or more consecutive days.
Example 2:
Input: s = "PPALLL" Output: false Explanation: The student was late 3 consecutive days in the last 3 days, so is not eligible for the award.
Constraints:
1 <= s.length <= 1000s[i] is either 'A', 'L', or 'P'.Problem summary: 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.
Start with the most direct exhaustive search. That gives a correctness anchor before optimizing.
Pattern signal: General problem-solving
"PPALLP"
"PPALLL"
student-attendance-record-ii)Source-backed implementations are provided below for direct study and interview prep.
// Accepted solution for LeetCode #551: Student Attendance Record I
class Solution {
public boolean checkRecord(String s) {
return s.indexOf("A") == s.lastIndexOf("A") && !s.contains("LLL");
}
}
// Accepted solution for LeetCode #551: Student Attendance Record I
func checkRecord(s string) bool {
return strings.Count(s, "A") < 2 && !strings.Contains(s, "LLL")
}
# Accepted solution for LeetCode #551: Student Attendance Record I
class Solution:
def checkRecord(self, s: str) -> bool:
return s.count('A') < 2 and 'LLL' not in s
// Accepted solution for LeetCode #551: Student Attendance Record I
struct Solution;
impl Solution {
fn check_record(s: String) -> bool {
let s: Vec<char> = s.chars().collect();
if s.iter().filter(|&c| c == &'A').count() > 1 {
return false;
}
if s.windows(3).filter(|&w| w == ['L', 'L', 'L']).count() > 0 {
return false;
}
true
}
}
#[test]
fn test() {
let s = "PPALLP".to_string();
assert_eq!(Solution::check_record(s), true);
let s = "PPALLLP".to_string();
assert_eq!(Solution::check_record(s), false);
}
// Accepted solution for LeetCode #551: Student Attendance Record I
function checkRecord(s: string): boolean {
return s.indexOf('A') === s.lastIndexOf('A') && s.indexOf('LLL') === -1;
}
Use this to step through a reusable interview workflow for this problem.
Two nested loops check every pair or subarray. The outer loop fixes a starting point, the inner loop extends or searches. For n elements this gives up to n²/2 operations. No extra space, but the quadratic time is prohibitive for large inputs.
Most array problems have an O(n²) brute force (nested loops) and an O(n) optimal (single pass with clever state tracking). The key is identifying what information to maintain as you scan: a running max, a prefix sum, a hash map of seen values, or two pointers.
Review these before coding to avoid predictable interview regressions.
Wrong move: Loop endpoints miss first/last candidate.
Usually fails on: Fails on minimal arrays and exact-boundary answers.
Fix: Re-derive loops from inclusive/exclusive ranges before coding.