Number of Senior Citizens

easy array string counting

Problem

You are given an array details of fixed-length strings. Each string has length 15 and encodes one passenger: characters 0..9 are the phone number, character 10 is the gender, characters 11..12 are the two-digit age, and characters 13..14 are the seat. Return how many passengers are strictly more than 60 years old.

Inputdetails = ["7868190130M7522","5303914400F9211","9273338290F4010"]
Output2
The three ages, read from positions 11–12, are 75, 92, and 40. Two of them exceed 60, so the answer is 2.

def countSeniors(details):
    count = 0
    for d in details:
        # characters at indices 11 and 12 form the age
        age = int(d[11:13])
        if age > 60:
            count += 1
    return count
function countSeniors(details) {
  let count = 0;
  for (const d of details) {
    // characters at indices 11 and 12 form the age
    const age = Number(d.slice(11, 13));
    if (age > 60) {
      count++;
    }
  }
  return count;
}
int countSeniors(String[] details) {
    int count = 0;
    for (String d : details) {
        // characters at indices 11 and 12 form the age
        int age = Integer.parseInt(d.substring(11, 13));
        if (age > 60) {
            count++;
        }
    }
    return count;
}
int countSeniors(vector<string>& details) {
    int count = 0;
    for (auto& d : details) {
        // characters at indices 11 and 12 form the age
        int age = stoi(d.substr(11, 2));
        if (age > 60) {
            count++;
        }
    }
    return count;
}
Time: O(n) Space: O(1)