Back to photostream

Student Attendance Record I Leetcode Solution

Problem statement

In the problem " Student Attendance Record I" we are given a string where each letter represents the attendance detail of a student. The interpretation of letters in the string is as follows:

 

- 'A' means absent.

- 'P' means present.

- 'L' means late

 

The student will be rewarded based on his attendance if he is not absent for more than one day or not late continuously for more than two days. Our task is to determine if the student will be rewarded or not.

Example

str="PPALLP"

true

Explanation:

 

As the student is not absent for more than one day and not late continuously for more than two days so he must be rewarded.

Approach for Student Attendance Record I Leetcode Solution

Implementation

This is a basic implementation problem. We need to find out if the student will be rewarded or not. So to reward the student we need to check if he is not absent for more than one day and not late continuously for more than two days. We will follow these steps to perform this check:

 

- Initialize number of 'A' count and 'L' count by zero

- Traverse the complete string.

 

- If the current character is 'A' then increment the count of 'A' by one.

- If the current character is 'L' then increment the count of 'L' by one.

- Otherwise, the count of 'L' becomes zero.

- Now check if the count of 'A' is greater than or equal to 2 or the count of 'L' is greater than 2. If the condition is true return false.

 

www.tutorialcup.com/leetcode-solutions/student-attendance...

9 views
0 faves
0 comments
Uploaded on September 14, 2021