""" 0551.1 - Solution 1 - Single Pass with Counters """
#####################################################################################
# Classes
#####################################################################################
class Solution:
"""Solution Class"""
def checkRecord(self, s: str) -> bool:
"""Check Record Function"""
absent_count = 0
late_streak = 0
for c in s:
if c == 'A':
absent_count += 1
if absent_count >= 2:
return False
late_streak = 0
elif c == 'L':
late_streak += 1
if late_streak >= 3:
return False
else:
late_streak = 0
return True
#####################################################################################
# Functions
#####################################################################################
def testcase():
"""Test Function"""
print(Solution().checkRecord("PPALLP")) # True
print(Solution().checkRecord("PPALLL")) # False
print(Solution().checkRecord("AA")) # False
print(Solution().checkRecord("LLLP")) # False
#####################################################################################
# Main
#####################################################################################
if __name__ == "__main__":
testcase()
""" 0551.2 - Solution 2 - Built-in String Methods """
#####################################################################################
# Classes
#####################################################################################
class Solution:
"""Solution Class"""
def checkRecord(self, s: str) -> bool:
"""Check Record Function"""
return s.count('A') < 2 and 'LLL' not in s
#####################################################################################
# Functions
#####################################################################################
def testcase():
"""Test Function"""
print(Solution().checkRecord("PPALLP")) # True
print(Solution().checkRecord("PPALLL")) # False
print(Solution().checkRecord("AA")) # False
print(Solution().checkRecord("LLLP")) # False
#####################################################################################
# Main
#####################################################################################
if __name__ == "__main__":
testcase()