You are given a string representing an attendance record for a student. The record only contains the following three characters:
A student could be rewarded if their attendance record does not contain:
You need to implement a function checkRecord(s: str) -> bool
that checks whether the student’s record is eligible for an attendance award.
No additional clarifications are needed, as the problem statement is clear. We need to return True
if the student is eligible based on the given conditions, and False
otherwise.
To achieve this, we can:
Here’s the Python implementation:
def checkRecord(s: str) -> bool:
# Check for more than one 'A'
if s.count('A') > 1:
return False
# Check for three consecutive 'L's
if 'LLL' in s:
return False
return True
Hence, the overall time complexity of the algorithm is O(n).
By keeping the solution straightforward using built-in string operations, it remains efficient and easy to understand.
Got blindsided by a question you didn’t expect?
Spend too much time studying?
Or simply don’t have the time to go over all 3000 questions?