Number of Senior Citizens - Problem
You are given a 0-indexed array of strings details. Each element of details provides information about a given passenger compressed into a string of length 15.
The system is such that:
- The first ten characters consist of the phone number of passengers.
- The next character denotes the gender of the person.
- The following two characters are used to indicate the age of the person.
- The last two characters determine the seat allotted to that person.
Return the number of passengers who are strictly more than 60 years old.
Input & Output
Example 1 — Mixed Ages
$
Input:
details = ["7868190130M7522","5303914400F9211","9273338640F4317"]
›
Output:
2
💡 Note:
First passenger: age 75 > 60 (senior), second passenger: age 92 > 60 (senior), third passenger: age 43 ≤ 60 (not senior). Total seniors: 2
Example 2 — No Seniors
$
Input:
details = ["1313579440F2036","2921522980M5644"]
›
Output:
0
💡 Note:
First passenger: age 20 ≤ 60, second passenger: age 56 ≤ 60. No seniors found.
Example 3 — All Seniors
$
Input:
details = ["9751302862F0693","3888560693F7262"]
›
Output:
1
💡 Note:
First passenger: age 06 ≤ 60, second passenger: age 72 > 60. Only one senior found.
Constraints
- 1 ≤ details.length ≤ 100
- details[i].length == 15
- details[i] consists of digits and an uppercase English letter
- All the phone numbers and seat numbers in the given strings are distinct
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code