O(n) || Beats 100 % Java  C++ | Python | Go | Rust | JavaScript
Concise Approach \n\n\n# Intuition\nThe problem requires counting the number of passengers who are over 60 years old. The key insight is that we don\'t need to 
## Concise Approach \n\n\n# Intuition\nThe problem requires counting the number of passengers who are over 60 years old. The key insight is that we don\'t need to convert the entire age to an integer; we can simply compare the characters representing the age digits. This allows for a more efficient solution without the need for string-to-integer conversion.\n\n# Approach\n1. Initialize a counter `seniorCount` to keep track of passengers over 60.\n2. Iterate through each passenger\'s details in the input array.\n3. For each passenger, extract the tens and ones digits of their age (located at indices 11 and 12 in the string).\n4. Compare these digits to determine if the age is over 60:\n   - If the tens digit is greater than \'6\', the person is over 60.\n   - If the tens digit is \'6\', check if the ones digit is greater than \'0\'.\n5. If either condition is true, increment the `seniorCount`.\n6. Return the final count of seniors.\n\n# Complexity\n- Time complexity: O(n), where n is the number of passengers (length of the input array).\n  We iterate through the array once, and for each string, we perform constant time operations.\n\n- Space complexity: O(1)\n  We only use a fixed amount of extra space (the `seniorCount` variable) regardless of the input size.\n\nNow, here are equivalent implementations in other languages:\n\n---\n\n```Java []\nclass Solution {\n    public int countSeniors(String[] details) {\n        int seniorCount = 0;\n        for (String info : details) {\n            char tens = info.charAt(11);\n            char ones = info.charAt(12);\n            if (tens > \'6\' || (tens == \'6\' && ones > \'0\')) {\n                seniorCount++;\n            }\n        }\n        return seniorCount;\n    }\n}\n\n```\n```cpp []\nclass Solution {\npublic:\n    int countSeniors(vector<string>& details) {\n        int seniorCount = 0;\n        for (const string& info : details) {\n            char tens = info[11];\n            char ones = info[12];\n            if (tens > \'6\' || (tens == \'6\' && ones > \'0\')) {\n                seniorCount++;\n            }\n        }\n        return seniorCount;\n    }\n};\n```\n\n\n```Python []\nclass Solution:\n    def countSeniors(self, details: List[str]) -> int:\n        return sum(info[11] > \'6\' or (info[11] == \'6\' and info[12] > \'0\') for info in details)\n```\n\n```Go []\nfunc countSeniors(details []string) int {\n    seniorCount := 0\n    for _, info := range details {\n        tens := info[11]\n        ones := info[12]\n        if tens > \'6\' || (tens == \'6\' && ones > \'0\') {\n            seniorCount++\n        }\n    }\n    return seniorCount\n}\n```\n\n```Rust []\nimpl Solution {\n    pub fn count_seniors(details: Vec<String>) -> i32 {\n        details.iter().filter(|&info| {\n            let tens = info.as_bytes()[11];\n            let ones = info.as_bytes()[12];\n            tens > b\'6\' || (tens == b\'6\' && ones > b\'0\')\n        }).count() as i32\n    }\n}\n```\n\n\n```Javascript []\n/**\n * @param {string[]} details\n * @return {number}\n */\nvar countSeniors = function(details) {\n    return details.reduce((count, info) => {\n        const tens = info[11];\n        const ones = info[12];\n        return count + (tens > \'6\' || (tens === \'6\' && ones > \'0\') ? 1 : 0);\n    }, 0);\n};\n```\n\n---\n## Approach 2:\n\n### Intuition\n\nThe initial thought process for this problem involves recognizing that the input consists of strings containing compressed passenger information, with the age being a key component to extract and evaluate. The straightforward approach might be to extract the full age and compare it to 60, but a more efficient solution presents itself upon closer examination.\n\nIt becomes apparent that fully calculating the age for every passenger is unnecessary. If the tens digit of the age is 7, 8, or 9, the person is undoubtedly over 60. Conversely, if it\'s 5 or less, they\'re definitely under 60. The only case requiring further investigation is when the tens digit is 6.\n\nThis realization leads to the development of a series of quick checks that allow for rapid decision-making in each case, potentially reducing the number of operations required per passenger.\n\n### Approach \n\nThe solution is structured as follows:\n\n1. Constants \n   - AGE_THRESHOLD: 60 (the age being checked against)\n   - TENS_DIGIT_THRESHOLD: \'6\' (the character for comparison with the tens digit)\n   - AGE_TENS_INDEX: 11 (position of the tens digit in the string)\n   - AGE_ONES_INDEX: 12 (position of the ones digit in the string)\n\n2. The main countSeniors method employs a simple for-loop to iterate through all passengers. For each passenger, the isOverSixty method is called to determine if they\'re a senior, incrementing a counter if true.\n\n3. The isOverSixty method implements the efficient checks:\n   \n   a. The tens digit of the age is extracted using charAt(AGE_TENS_INDEX).\n   \n   b. If this digit is greater than \'6\', the person is over 60, and true is immediately returned. This efficiently handles all cases for ages 70 and above.\n   \n   c. If the tens digit is less than \'6\', the person is under 60, and false is immediately returned. This efficiently handles all cases for ages 59 and below.\n   \n   d. If the tens digit is exactly \'6\', the ones digit is checked. If it\'s greater than \'0\', the person is over 60; otherwise, they\'re exactly 60 and don\'t count as a senior by the given definition.\n\nThis approach is efficient because most ages can be determined by checking only one or two characters. It avoids string parsing or integer conversion, which can be relatively expensive operations.\n\n### Complexity\n\n- **Time complexity: O(n)**, where n is the number of passengers (the length of the details array). The array is iterated through once, and for each passenger, at most two constant-time operations (checking two characters) are performed. Despite the nested operations (the loop and the isOverSixty method), the overall complexity remains linear.\n\n- **Space complexity: O(1)**. A fixed amount of extra space is used regardless of the input size. A few constants and a single integer counter are employed, but these don\'t grow with the input size.\n\n---\n### Code\n```Java []\nclass Solution {\n    private static final int AGE_THRESHOLD = 60;\n    private static final char TENS_DIGIT_THRESHOLD = \'6\';\n    private static final int AGE_TENS_INDEX = 11;\n    private static final int AGE_ONES_INDEX = 12;\n    public int countSeniors(String[] details) {\n        int seniorCount = 0;\n        for (String passenger : details) {\n            if (isOverSixty(passenger)) {\n                seniorCount++;\n            }\n        }\n        return seniorCount;\n    }\n    private boolean isOverSixty(String passenger) {\n        char tensDigit = passenger.charAt(AGE_TENS_INDEX);\n        if (tensDigit > TENS_DIGIT_THRESHOLD) {\n            return true;\n        }\n        if (tensDigit == TENS_DIGIT_THRESHOLD) {\n            return passenger.charAt(AGE_ONES_INDEX) > \'0\';\n        }\n        return false;\n    }\n}\n```\n```C++ []\nclass Solution {\nprivate:\n    static const int AGE_THRESHOLD = 60;\n    static const char TENS_DIGIT_THRESHOLD = \'6\';\n    static const int AGE_TENS_INDEX = 11;\n    static const int AGE_ONES_INDEX = 12;\n    \n    bool isOverSixty(const string& passenger) {\n        char tensDigit = passenger[AGE_TENS_INDEX];\n        if (tensDigit > TENS_DIGIT_THRESHOLD) {\n            return true;\n        }\n        if (tensDigit == TENS_DIGIT_THRESHOLD) {\n            return passenger[AGE_ONES_INDEX] > \'0\';\n        }\n        return false;\n    }\n\npublic:\n    int countSeniors(vector<string>& details) {\n        int seniorCount = 0;\n        for (const auto& passenger : details) {\n            if (isOverSixty(passenger)) {\n                seniorCount++;\n            }\n        }\n        return seniorCount;\n    }\n};\n```\n```Python []\nclass Solution:\n    AGE_THRESHOLD = 60\n    TENS_DIGIT_THRESHOLD = \'6\'\n    AGE_TENS_INDEX = 11\n    AGE_ONES_INDEX = 12\n\n    def countSeniors(self, details: List[str]) -> int:\n        return sum(self.isOverSixty(passenger) for passenger in details)\n\n    def isOverSixty(self, passenger: str) -> bool:\n        tens_digit = passenger[self.AGE_TENS_INDEX]\n        if tens_digit > self.TENS_DIGIT_THRESHOLD:\n            return True\n        if tens_digit == self.TENS_DIGIT_THRESHOLD:\n            return passenger[self.AGE_ONES_INDEX] > \'0\'\n        return False\n```\n```Go []\npackage main\n\nconst (\n    AGE_THRESHOLD        = 60\n    TENS_DIGIT_THRESHOLD = \'6\'\n    AGE_TENS_INDEX       = 11\n    AGE_ONES_INDEX       = 12\n)\n\nfunc countSeniors(details []string) int {\n    seniorCount := 0\n    for _, passenger := range details {\n        if isOverSixty(passenger) {\n            seniorCount++\n        }\n    }\n    return seniorCount\n}\n\nfunc isOverSixty(passenger string) bool {\n    tensDigit := passenger[AGE_TENS_INDEX]\n    if tensDigit > TENS_DIGIT_THRESHOLD {\n        return true\n    }\n    if tensDigit == TENS_DIGIT_THRESHOLD {\n        return passenger[AGE_ONES_INDEX] > \'0\'\n    }\n    return false\n}\n```\n```Rust []\nimpl Solution {\n    const AGE_THRESHOLD: i32 = 60;\n    const TENS_DIGIT_THRESHOLD: char = \'6\';\n    const AGE_TENS_INDEX: usize = 11;\n    const AGE_ONES_INDEX: usize = 12;\n\n    pub fn count_seniors(details: Vec<String>) -> i32 {\n        details.iter().filter(|&passenger| Self::is_over_sixty(passenger)).count() as i32\n    }\n\n    fn is_over_sixty(passenger: &str) -> bool {\n        let tens_digit = passenger.chars().nth(Self::AGE_TENS_INDEX).unwrap();\n        if tens_digit > Self::TENS_DIGIT_THRESHOLD {\n            return true;\n        }\n        if tens_digit == Self::TENS_DIGIT_THRESHOLD {\n            return passenger.chars().nth(Self::AGE_ONES_INDEX).unwrap() > \'0\';\n        }\n        false\n    }\n}\n```\n```JavaScript []\n/**\n * @param {string[]} details\n * @return {number}\n */\nvar countSeniors = function(details) {\n    return details.filter(isOverSixty).length;\n};\n\n/**\n * Check if a passenger is over 60 years old\n * @param {string} passenger\n * @return {boolean}\n */\nfunction isOverSixty(passenger) {\n    const AGE_TENS_INDEX = 11;\n    const AGE_ONES_INDEX = 12;\n    const TENS_DIGIT_THRESHOLD = \'6\';\n\n    const tensDigit = passenger[AGE_TENS_INDEX];\n    if (tensDigit > TENS_DIGIT_THRESHOLD) {\n        return true;\n    }\n    if (tensDigit === TENS_DIGIT_THRESHOLD) {\n        return passenger[AGE_ONES_INDEX] > \'0\';\n    }\n    return false;\n}\n\n```\n\n\n---\n## Approach 3:\n\n### Intuition\n\nTry extracting age information from strings containing compressed passenger data, and then determining if the age exceeds 60. A straightforward approach suggests itself: extract the age, convert it to a number, and compare it to the threshold.\n\nThis method, while potentially doing more work than necessary for some ages, would handle all scenarios uniformly. By breaking it down into separate steps (extracting the age, converting to a number, comparing), the code can be made clear and easy to understand.\n\n### Approach\n\nThe solution is structured as follows:\n\n1. Constants:\n   - ELDERLY_THRESHOLD: 60 (the age being checked against)\n   - AGE_TENS_INDEX: 11 (position of the tens digit in the string)\n   - AGE_ONES_INDEX: 12 (position of the ones digit in the string)\n\n2. The main countSeniors method uses a straightforward for-loop to iterate through all passengers. For each passenger, the calculateAge method is called to obtain their age, which is then compared to the ELDERLY_THRESHOLD. The counter is incremented if the age is greater.\n\n3. The calculateAge method performs the core operations:\n   \n   a. The tens digit and ones digit are extracted separately using charAt.\n   \n   b. Each of these characters is converted to its numeric value using the charToDigit method.\n   \n   c. Simple arithmetic combines them into a two-digit number: tens * 10 + ones.\n\n4. The charToDigit method employs a clever trick. Since the ASCII values of the digits \'0\' to \'9\' are consecutive, a digit character can be converted to its numeric value by subtracting the ASCII value of \'0\'. Thus, \'0\' - \'0\' = 0, \'1\' - \'0\' = 1, and so on.\n\nThis approach is straightforward and easy to comprehend. It treats all ages uniformly, making the logic very consistent. The same operations are always performed: extract the digits, convert to numbers, combine into an age, and compare to the threshold.\n\n### Complexity\n\n- **Time complexity: O(n)**, where n is the number of passengers (the length of the details array). The array is iterated through once, and for each passenger, a fixed number of operations are performed (extracting two characters, converting them to digits, combining them, and comparing to the threshold). These operations take constant time, so despite the nested operations (the loop and the calculateAge method), the overall complexity remains linear.\n\n- **Space complexity: O(1)**. A fixed amount of extra space is used regardless of the input size. A few constants and a single integer counter are employed, but these don\'t grow with the input size.\n\n---\n### Code\n```Java []\nclass Solution {\n    private static final int ELDERLY_THRESHOLD = 60;\n    private static final int AGE_TENS_INDEX = 11;\n    private static final int AGE_ONES_INDEX = 12;\n    public int countSeniors(String[] details) {\n        int elderlyCount = 0;\n\n        for (String passengerInfo : details) {\n            if (calculateAge(passengerInfo) > ELDERLY_THRESHOLD) {\n                elderlyCount++;\n            }\n        }\n\n        return elderlyCount;\n    }\n\n    private int calculateAge(String info) {\n        int tens = charToDigit(info.charAt(AGE_TENS_INDEX));\n        int ones = charToDigit(info.charAt(AGE_ONES_INDEX));\n        return tens * 10 + ones;\n    }\n\n    private int charToDigit(char c) {\n        return c - \'0\';\n    }\n}\n```\n```C++ []\nclass Solution {\nprivate:\n    static const int ELDERLY_THRESHOLD = 60;\n    static const int AGE_TENS_INDEX = 11;\n    static const int AGE_ONES_INDEX = 12;\n    \n    int calculateAge(const string& info) {\n        int tens = charToDigit(info[AGE_TENS_INDEX]);\n        int ones = charToDigit(info[AGE_ONES_INDEX]);\n        return tens * 10 + ones;\n    }\n    \n    int charToDigit(char c) {\n        return c - \'0\';\n    }\n\npublic:\n    int countSeniors(vector<string>& details) {\n        int elderlyCount = 0;\n        for (const auto& passengerInfo : details) {\n            if (calculateAge(passengerInfo) > ELDERLY_THRESHOLD) {\n                elderlyCount++;\n            }\n        }\n        return elderlyCount;\n    }\n};\n```\n```Python []\nclass Solution:\n    ELDERLY_THRESHOLD = 60\n    AGE_TENS_INDEX = 11\n    AGE_ONES_INDEX = 12\n\n    def countSeniors(self, details: List[str]) -> int:\n        return sum(self.calculateAge(info) > self.ELDERLY_THRESHOLD for info in details)\n\n    def calculateAge(self, info: str) -> int:\n        tens = self.charToDigit(info[self.AGE_TENS_INDEX])\n        ones = self.charToDigit(info[self.AGE_ONES_INDEX])\n        return tens * 10 + ones\n\n    def charToDigit(self, c: str) -> int:\n        return ord(c) - ord(\'0\')\n```\n```Go []\npackage main\n\nconst (\n    ELDERLY_THRESHOLD = 60\n    AGE_TENS_INDEX    = 11\n    AGE_ONES_INDEX    = 12\n)\n\nfunc countSeniors(details []string) int {\n    elderlyCount := 0\n    for _, passengerInfo := range details {\n        if calculateAge(passengerInfo) > ELDERLY_THRESHOLD {\n            elderlyCount++\n        }\n    }\n    return elderlyCount\n}\n\nfunc calculateAge(info string) int {\n    tens := charToDigit(info[AGE_TENS_INDEX])\n    ones := charToDigit(info[AGE_ONES_INDEX])\n    return tens*10 + ones\n}\n\nfunc charToDigit(c byte) int {\n    return int(c - \'0\')\n}\n```\n```Rust []\nimpl Solution {\n    const ELDERLY_THRESHOLD: i32 = 60;\n    const AGE_TENS_INDEX: usize = 11;\n    const AGE_ONES_INDEX: usize = 12;\n\n    pub fn count_seniors(details: Vec<String>) -> i32 {\n        details.iter().filter(|&info| Self::calculate_age(info) > Self::ELDERLY_THRESHOLD).count() as i32\n    }\n\n    fn calculate_age(info: &str) -> i32 {\n        let tens = Self::char_to_digit(info.chars().nth(Self::AGE_TENS_INDEX).unwrap());\n        let ones = Self::char_to_digit(info.chars().nth(Self::AGE_ONES_INDEX).unwrap());\n        tens * 10 + ones\n    }\n\n    fn char_to_digit(c: char) -> i32 {\n        c as i32 - \'0\' as i32\n    }\n}\n```\n```JavaScript []\n/**\n * @param {string[]} details\n * @return {number}\n */\nvar countSeniors = function(details) {\n    const ELDERLY_THRESHOLD = 60;\n    const AGE_TENS_INDEX = 11;\n    const AGE_ONES_INDEX = 12;\n\n    // Function to convert character to its digit value\n    function charToDigit(c) {\n        return c.charCodeAt(0) - \'0\'.charCodeAt(0);\n    }\n\n    // Function to calculate age from the string\n    function calculateAge(info) {\n        const tens = charToDigit(info[AGE_TENS_INDEX]);\n        const ones = charToDigit(info[AGE_ONES_INDEX]);\n        return tens * 10 + ones;\n    }\n\n    // Count the number of seniors\n    let elderlyCount = 0;\n    for (const passengerInfo of details) {\n        if (calculateAge(passengerInfo) > ELDERLY_THRESHOLD) {\n            elderlyCount++;\n        }\n    }\n\n    return elderlyCount;\n};\n\n\n```\n---\n\nWhile these three approaches might seem similar at first glance but they actually use distinctly different problem-solving strategies and computational methods. \n\nThe key differences lie in how they interpret and process the age data:\n\n**Concise Approach** operates at the lowest level, directly comparing character values without any conversion or calculation, making it potentially the most efficient but least flexible. \n**Approach 2** introduces a more abstract, rule-based system with separate methods and constants, improving readability and maintainability at the cost of slightly more complex logic. \n**Approach 3** takes a more intuitive route by fully calculating the age as an integer before comparison, which is the most straightforward to understand and modify but potentially the least efficient due to the additional arithmetic operations. \n
['Array', 'String', 'C++', 'Java', 'Go', 'Python3', 'Rust', 'JavaScript']