Skip to main content
Back to problems
Leetcode
Medium
Arrays
Strings
Simulation
Student Attendance Record I

Determine whether a student's attendance record is acceptable under simple absence and lateness rules.

Acceptance 0%
Problem Statement

Problem

You are given a string representing a student's attendance record over several days.

Each character is one of:

  • A for an absence
  • L for being late
  • P for being present

An attendance record is considered acceptable if:

  1. It contains at most one A.
  2. It does not contain three or more consecutive L characters.

Return whether the record is valid.

Notes

You only need to check the whole string once. The task is to validate the sequence against the two rules above.

Input Format

  • A single string s consisting only of the characters A, L, and P.

Output Format

  • Return true if the record is acceptable, otherwise return false.

Constraints

  • 1 <= s.length <= 1000 is a reasonable interview-style assumption for this problem.
  • s[i] ∈ { 'A', 'L', 'P' }.
  • The record is valid only if it has at most one A and no substring LLL.
Examples
Sample cases returned by the problem API.

Example 1

Input

s = "PPALLP"

Output

true

Explanation

There is one absence and no three consecutive lates.

Example 2

Input

s = "PPALLL"

Output

false

Explanation

The record contains three consecutive L characters at the end.

Show 1 more example

Example 3

Input

s = "PAAP"

Output

false

Explanation

The record contains two absences.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.