C++ | Efficient Counting of Senior Citizens | 0ms Beats 100.00%
Intuition\nTo determine the number of senior citizens in a given list of passenger details, we need to extract and evaluate the age information from each entry.
# Intuition\nTo determine the number of senior citizens in a given list of passenger details, we need to extract and evaluate the age information from each entry. Since the age is located at the 11th and 12th positions in each string, we can easily parse these characters, convert them to integers, and check if they represent an age greater than 60.\n\n# Approach\nTo efficiently count the number of senior citizens, we use the **count_if** function from the C++ **Standard Library** to iterate through each passenger detail. In the lambda function, we access characters at positions 11 and 12 to form the age, convert these characters to an integer, and check if the age exceeds 60. The function then returns the count of passengers meeting this criterion.\n\n# Complexity\n- Time complexity $$\uD835\uDC42(\uD835\uDC5B)$$, where $$\uD835\uDC5B$$ is the number of passenger details, as each detail string is processed once.\n- Space complexity $$\uD835\uDC42(1)$$, requiring only a constant amount of extra space for the lambda function.\n\n# Code\n```\nclass Solution {\npublic:\n    int countSeniors(vector<string>& details) {\n        return count_if(details.begin(), details.end(), [](const string& d) { \n            return (d[11] - \'0\') * 10 + (d[12] - \'0\') > 60; \n        });\n    }\n};\n\n```\n## **If you found this solution helpful, please upvote! \uD83D\uDE0A**
['C++']