Number of Senior Citizens - Problem
You're working as a data analyst for an airline company and need to identify senior citizens from passenger records for special assistance services.
Given a 0-indexed array of strings called details, where each string contains compressed passenger information in a fixed 15-character format:
- Characters 0-9: Phone number (10 digits)
- Character 10: Gender ('M' or 'F')
- Characters 11-12: Age (2 digits, e.g., '65', '42')
- Characters 13-14: Seat number (2 characters)
Goal: Return the count of passengers who are strictly older than 60 years (age > 60).
Example: If a passenger string is "7868190130M7522", the age is 75 (characters 11-12), so this passenger counts as a senior citizen.
Input & Output
example_1.py โ Basic Case
$
Input:
["7868190130M7522", "5303914400F9211", "9273338640F4823"]
โบ
Output:
2
๐ก Note:
First passenger: age 75 > 60 โ, Second passenger: age 92 > 60 โ, Third passenger: age 48 โค 60 โ. Total: 2 seniors
example_2.py โ Edge Case
$
Input:
["1313579440F2036", "2921522980M5644"]
โบ
Output:
0
๐ก Note:
First passenger: age 20 โค 60, Second passenger: age 56 โค 60. No passengers are over 60, so count is 0
example_3.py โ Boundary Case
$
Input:
["9751302862F0693", "3888560693F7262", "5485983835F0649"]
โบ
Output:
1
๐ก Note:
Ages are 06, 72, and 06 respectively. Only the second passenger (age 72) is over 60. Count is 1
Constraints
- 1 โค details.length โค 500
- details[i].length == 15
- details[i] consists of digits and an uppercase English letter
- All phone numbers and seat numbers are distinct
- Age is always a valid 2-digit number (00-99)
Visualization
Tap to expand
Understanding the Visualization
1
Setup Scanner
Initialize counter and prepare to scan boarding passes
2
Scan Pass
Read the 15-character boarding pass data
3
Locate Age
Extract digits from positions 11-12 (age section)
4
Check Senior Status
Convert age to number and check if > 60
5
Update Count
Increment senior citizen counter if applicable
Key Takeaway
๐ฏ Key Insight: String manipulation with fixed positions allows for direct, efficient data extraction - no complex algorithms needed, just precise indexing!
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code