Problem 154517 · medium · Phase 01 Prerequisites & Setup

Longest Attendance Streak

nested loops · strings · lists

records is a list of [name, attendance] pairs where attendance is a string of P (present) and A (absent), one character per day. For each student return [name, streak] where streak is the length of their longest run of consecutive P days. Keep the students in the given order.

Examples

Input:  records = [["ana", "PPAP"], ["bo", "AAAA"]]
Output: [["ana", 2], ["bo", 0]]

Input:  records = [["cy", "PPPP"]]
Output: [["cy", 4]]

Constraints

  • 0 <= len(records) <= 200, 0 <= len(attendance) <= 400

Goals

  • Find the longest run of one character in a string
  • Repeat a per-item computation for every record and collect results
Starting Python…