FastPrepLongest All-Present Attendance Streak

Longest All-Present Attendance Streak

Agoda logoAgodaEasyFULLTIMEPHONE SCREEN
Learn

Problem statement

You are given daily attendance records in attendance. Each string represents one day, each position represents the same employee across all days, 'Y' means present, and 'N' means absent.

Return the maximum number of consecutive days on which every employee was present. A day qualifies only when every character in its record is 'Y'. Return 0 when no day qualifies.

Function

longestAllPresentStreak(attendance: String[]) → int

Examples

Example 1

attendance = ["YYY","YYY","YNY","YYY"]return = 2

The first two days form the longest all-present streak.

Example 2

attendance = ["NN","YN","NY"]return = 0

Every day has at least one absence.

Example 3

attendance = ["Y","Y","Y"]return = 3

All three days qualify.

Constraints

  • 1 <= attendance.length <= 10^5.
  • 1 <= attendance[i].length <= 100.
  • All strings have the same length and contain only 'Y' and 'N'.

More Agoda problems

See Agoda hiring insights
public int longestAllPresentStreak(String[] attendance) {
    // Write your solution here.
}
attendance["YYY","YYY","YNY","YYY"]
expected2
Checking account…