Problem Description
Explanation:
- Iterate through the array of details.
- Extract the age information from each element.
- Check if the age is strictly greater than 60.
- Increment a counter for each passenger who is over 60.
- Return the total count of senior citizens.
Time Complexity: O(n) where n is the number of elements in the details array.
Space Complexity: O(1)
Solutions
class Solution {
public int numSeniorCitizens(String[] details) {
int count = 0;
for (String detail : details) {
int age = Integer.parseInt(detail.substring(11, 13));
if (age > 60) {
count++;
}
}
return count;
}
}
Loading editor...