Problem Description
Given an array of strings where each string is a 15-character compressed representation of a passenger's details, determine how many passengers are strictly more than 60 years old. The structure of each string is as follows:
- First 10 characters: phone number
- 11th character: gender ('M', 'F', or 'O')
- Characters 12-13: age (as a two-digit number)
- Last 2 characters: seat number
The task is to count the number of passengers with age strictly > 60.
Key Insights
- The age of each passenger is embedded in two characters in the string.
- Convert the substring representing the age into an integer.
- Simply iterate through each detail and count those with an age greater than 60.
- String slicing and integer conversion are sufficient without additional data structures.
Space and Time Complexity
Time Complexity: O(n) where n is the number of detail strings. Space Complexity: O(1) additional space.
Solution
The solution involves iterating through each string in the provided array. For each string, extract the substring that represents the age (located at positions 11 and 12 with 0-indexing adjustments) and convert it to an integer. If the age is greater than 60, increment a counter. This approach leverages basic string operations and conditional checking, ensuring simplicity and efficiency.