2678. Number of Senior Citizens #182
Answered
by
mah-shamim
mah-shamim
asked this question in
Q&A
-
You are given a 0-indexed array of strings
Return the number of passengers who are strictly more than 60 years old. Example 1:
Example 2:
Constraints:
Hint:
|
Beta Was this translation helpful? Give feedback.
Answered by
mah-shamim
Aug 1, 2024
Replies: 1 comment 3 replies
-
To solve this problem, we can follow these steps:
Let's implement this solution in PHP: 2678. Number of Senior Citizens <?php
function countSeniorCitizens($details) {
$seniorCount = 0;
foreach ($details as $detail) {
// Extract the age part of the string
$age = intval(substr($detail, 11, 2));
// Check if the age is strictly greater than 60
if ($age > 60) {
$seniorCount++;
}
}
return $seniorCount;
}
// Example usage:
$details1 = ["7868190130M7522","5303914400F9211","9273338290F4010"];
$details2 = ["1313579440F2036","2921522980M5644"];
echo countSeniorCitizens($details1); // Output: 2
echo countSeniorCitizens($details2); // Output: 0
?> Explanation:
Testing:
This solution is efficient and straightforward, working within the constraints provided. |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
kovatz
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To solve this problem, we can follow these steps:
Let's implement this solution in PHP: 2678. Number of Senior Citizens