Skip to content

2678. Number of Senior Citizens #182

Answered by mah-shamim
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

To solve this problem, we can follow these steps:

  1. Extract the Age: The age is located at the 12th and 13th positions in each string.
  2. Convert to Integer: Convert the extracted age substring to an integer.
  3. Count Senior Citizens: Count how many of these ages are strictly greater than 60.

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++;
        }
    }

    r…

Replies: 1 comment 3 replies

Comment options

mah-shamim
Aug 1, 2024
Maintainer Author

You must be logged in to vote
3 replies
@kovatz
Comment options

kovatz Aug 1, 2024
Collaborator

@topugit
Comment options

topugit Aug 1, 2024
Collaborator

@basharul-siddike
Comment options

Answer selected by kovatz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested easy Difficulty
4 participants