Detailed solution in C++ 🧩🔥 || JAVA ☕⭐ || Python 🐍✅ || Javascript 🌐🔥
\n# Problem Breakdown\n\nInput:\n- An array of strings, where each string is exactly 15 characters long.\n- Each string encodes the following information:\n  - 
\n# Problem Breakdown\n\n**Input**:\n- An array of strings, where each string is exactly 15 characters long.\n- Each string encodes the following information:\n  - **First 10 characters**: Phone number (not needed for solving this problem).\n  - **11th character**: Gender (not needed for solving this problem).\n  - **12th and 13th characters**: Age (important for solving this problem).\n  - **14th and 15th characters**: Seat number (not needed for solving this problem).\n\n**Output**:\n- An integer representing the number of passengers whose age is strictly greater than 60.\n\n# Approach\n\n1. **Extract Age Information**:\n   - For each passenger record, the age is encoded in characters at index 11 and 12 of the string.\n   - These characters need to be extracted and converted into an integer for comparison.\n\n2. **Check Age Condition**:\n   - Once the age is extracted and converted, compare it to 60.\n   - Count how many of these extracted ages are greater than 60.\n\n# Detailed Code Explanation\n\nLet\'s break down the Java code line by line:\n\n- This defines a class `Solution` with a method `countSeniors` that takes an array of strings (`details`) and returns an integer.\n\n\n- `count` is initialized to zero. This will be used to keep track of how many passengers are older than 60 years.\n\n- A `for` loop is used to iterate over each string in the `details` array.\n\n- `substring(11, 13)` extracts the substring from index 11 to 12 (inclusive of 11, exclusive of 13) from the current record. This gives us the two characters that represent the age.\n\n\n- `Integer.parseInt(s)` converts the extracted substring (which is a string representation of the age) into an integer.\n- The `if` statement checks if this integer is greater than 60.\n\n\n- If the age is greater than 60, `count` is incremented by 1.\n\n\n- After iterating through all records and counting the seniors, the method returns the final count.\n\n### Example Walkthrough\n\nConsider the input:\n\n```java\ndetails = ["7868190130M7522", "5303914400F9211", "9273338290F4010"]\n```\n\n- **First record**: `"7868190130M7522"`\n  - Age substring: `"75"`\n  - `75 > 60` is true, so count is incremented.\n\n- **Second record**: `"5303914400F9211"`\n  - Age substring: `"92"`\n  - `92 > 60` is true, so count is incremented.\n\n- **Third record**: `"9273338290F4010"`\n  - Age substring: `"40"`\n  - `40 > 60` is false, so count remains unchanged.\n\nFinal count: 2.\n\n### Complexity Analysis\n\n- **Time Complexity**:\n  - The `for` loop iterates over each element in the array. The substring extraction and integer conversion are constant-time operations for each string.\n  - Thus, the time complexity is O(n), where `n` is the number of passenger records.\n\n- **Space Complexity**:\n  - Only a few integer variables (`count` and the loop index `i`) are used, regardless of the input size.\n  - Hence, the space complexity is O(1).\n  \n```javascript []\nclass Solution {\n    countSeniors(details) {\n        let count = 0;\n        for (let i = 0; i < details.length; i++) {\n            let ageStr = details[i].substring(11, 13);\n            let age = parseInt(ageStr, 10);\n            if (age > 60) {\n                count++;\n            }\n        }\n        return count;\n    }\n}\n\n```\n```python []\nclass Solution:\n    def countSeniors(self, details):\n        count = 0\n        for detail in details:\n            age_str = detail[11:13]\n            age = int(age_str)\n            if age > 60:\n                count += 1\n        return count\n\n```\n```C++ []\n\nclass Solution {\npublic:\n    int countSeniors(const std::vector<std::string>& details) {\n        int count = 0;\n        for (const std::string& detail : details) {\n            std::string ageStr = detail.substr(11, 2);\n            int age = std::stoi(ageStr);\n            if (age > 60) {\n                count++;\n            }\n        }\n        return count;\n    }\n};\n\n```\n```JAVA []\nclass Solution {\n    public int countSeniors(String[] details) {\n       int count=0;\n       for(int i=0;i<details.length;i++){\n        String s= details[i].substring(11,13);\n        if(Integer.parseInt(s)>60){\n            count++;\n        }\n       } \n       return count;\n    }\n}\n```\n![UP.png](https://assets.leetcode.com/users/images/aef40363-b509-4c59-b44a-ee1e94e763a4_1722485432.641585.png)\n
['Array', 'String', 'Python', 'C++', 'Java', 'JavaScript']