In "Student Attendance Record I," you are given a string representing a student's attendance for a semester. The characters are 'A' (Absent), 'L' (Late), and 'P' (Present). A student is eligible for an attendance award if they meet two conditions:
true if the student is eligible, and false otherwise. It is a straightforward string-checking problem.Google and Bloomberg use this as an introductory question for early-career roles or as a quick coding warm-up. It tests basic string iteration, counting, and the ability to track "consecutive" states. While simple, it requires the candidate to correctly handle the logic of "consecutive" vs. "total" counts. It's a test of whether you can write clean, readable code for a set of clear business rules.
The pattern used is a simple Linear Scan (O(n) time). You iterate through the string once, keeping a counter for the total number of 'A's and another counter for the current run of consecutive 'L's. If the 'A' count reaches 2, or the 'L' run reaches 3, you can immediately return false. If you finish the string without violating the rules, you return true.
Attendance: "PPALLL"
A common mistake is not resetting the "consecutive late" counter when a character other than 'L' is encountered. Another mistake is using a slow string search method (like searching for "LLL" and then counting 'A's separately) when a single pass is more efficient. Some candidates might also misread the requirements, such as checking for 2 consecutive absences instead of 2 total absences.
For the Student Attendance Record I interview question, focus on writing the most concise and efficient code possible. A single loop with simple if conditions is best. Mention to your interviewer that you are using O(1) extra space and O(n) time, which is the optimal complexity for this problem.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Count Asterisks | Easy | Solve | |
| Flip Game | Easy | Solve | |
| Generate a String With Characters That Have Odd Counts | Easy | Solve | |
| Goal Parser Interpretation | Easy | Solve | |
| License Key Formatting | Easy | Solve |