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
Airport Senior Citizen Scanner๐Ÿ›‚ Security ScannerProcessing passenger boarding passes...50% CompleteSample Boarding Pass7868190130M7522Phone | G | Age | SeatAge Extraction Process75โ†’Age: 75โœ“75 > 60: Senior!๐Ÿ‘ฅ Senior Count2passengers need assistance
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!
Asked in
Amazon 15 Microsoft 8 Google 5 Apple 3
28.5K Views
Medium Frequency
~8 min Avg. Time
892 Likes
Ln 1, Col 1
Smart Actions
๐Ÿ’ก Explanation
AI Ready
๐Ÿ’ก Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen