Simple Java || C++ Code ☠️
java []\nclass Solution {\n    public int countSeniors(String[] details) {\n        int n = details.length;\n        int count=0;\n        for(int i=0;i<n;i++){
```java []\nclass Solution {\n    public int countSeniors(String[] details) {\n        int n = details.length;\n        int count=0;\n        for(int i=0;i<n;i++){\n            String str = details[i];\n            int x = Integer.parseInt(str.substring(11,13));\n            if(x>60){\n                count++;\n            }\n        }\n        return count;\n    }\n}\n```\n```C++ []\nclass Solution {\npublic:\n    int countSeniors(vector<string>& details) {\n        int n = details.size();\n        int count=0;\n        for(int i=0;i<n;i++){\n            string str = details[i];\n            int x = stoi(str.substr(11,2));\n            if(x>60){\n                count++;\n            }\n        }\n        return count;\n    }\n};\n```\n\n\n\n\n### Problem Statement\nYou are given an array of strings `details`. Each string in `details` contains information about a passenger in the following format:\n- The first ten characters: Phone number of the passenger.\n- The next character: Gender of the passenger.\n- The following two characters: Age of the passenger.\n- The last two characters: Seat allotted to the passenger.\n\nYour task is to count and return the number of passengers who are strictly more than 60 years old.\n\n\n### Detailed Explanation\n1. **Initialization:**\n   ```java\n   int n = details.length;\n   int count = 0;\n   ```\n   - `n` is the length of the `details` array.\n   - `count` is initialized to 0 to keep track of the number of passengers who are strictly more than 60 years old.\n\n2. **Iterating through the array:**\n   ```java\n   for(int i = 0; i < n; i++){\n       String str = details[i];\n   ```\n   - Loop through each string in the `details` array.\n\n3. **Extracting and Parsing Age:**\n   ```java\n   int x = Integer.parseInt(str.substring(11, 13));\n   ```\n   - `str.substring(11, 13)` extracts the age part from the string (characters at positions 11 and 12).\n   - `Integer.parseInt` converts the extracted substring to an integer.\n\n4. **Checking Age Condition:**\n   ```java\n   if(x > 60){\n       count++;\n   }\n   ```\n   - If the extracted age `x` is greater than 60, increment the `count`.\n\n5. **Return the Result:**\n   ```java\n   return count;\n   ```\n   - Finally, return the count of passengers who are strictly more than 60 years old.\n\n### Example\nConsider the following `details` array:\n```java\nString[] details = {\n    "1234567890M61A1",\n    "0987654321F45B2",\n    "5678901234M65C3",\n    "6789012345F62D4"\n};\n```\n- For "1234567890M61A1", age is 61 (greater than 60) -> count = 1\n- For "0987654321F45B2", age is 45 (not greater than 60) -> count remains 1\n- For "5678901234M65C3", age is 65 (greater than 60) -> count = 2\n- For "6789012345F62D4", age is 62 (greater than 60) -> count = 3\n\nSo, the method will return `3`.\n\n### Time and Space Complexity\n- **Time Complexity:** O(n), where `n` is the number of strings in the `details` array. This is because we are iterating through each string once.\n- **Space Complexity:** O(1), as we are using a constant amount of extra space regardless of the input size.\n\n\n
['Array', 'String', 'C++', 'Java']