Tuesday, May 16, 2017

Student Attendance Record I

Problem Statement

You are given a string representing an attendance record for a student. The record only contains the following three characters:
  1. 'A' : Absent.
  2. 'L' : Late.
  3. 'P' : Present.
A student could be rewarded if his attendance record doesn't contain more than one 'A' (absent) or more than two continuous 'L' (late).
You need to return whether the student could be rewarded according to his attendance record.

Link to GitHub:Code


Example :
Input: "PPALLP"
Output: True

Input: "PPALLL"
Output: False

Solution


  • This would be an easy solution. We need to have the matching regular expression to check if the allowed characters are available in the string

public static boolean get(String s){
  //Using regular expression. If LL is more than 2 continuous 
                //and A is more than 2.
  return s.matches(".*LLL*.|.*A.*A.");
 }

No comments:

Post a Comment