2678. Number of Senior Citizens
EasyView on LeetCode
Time: O(n)
Space: O(1)
Problem Overview
Number of Senior Citizens (Easy) asks you to solve a structured algorithmic task. This is a common Array / String pattern in coding interviews. Parse age from chars at index 11-12 of each detail string; count those > 60.
A full step-by-step explanation is being added. See the study guide for pattern-based practice.
Approach
Parse age from chars at index 11-12 of each detail string; count those > 60.
Related patterns: Array, String, Simulation
2678.cs
C#
// Approach: Parse age from chars at index 11-12 of each detail string; count those > 60.
// Time: O(n) Space: O(1)
public class Solution
{
public int CountSeniors(string[] details)
{
// foreach(string d in details)
// Console.WriteLine(d.Substring(11, 2));
return details.Where(x => Int32.Parse(x.Substring(11, 2)) > 60).Count();
}
}Was this solution helpful?
Related Problems
- 4. Median of Two Sorted Arrays(Hard)
- 11. Container With Most Water(Medium)
- 12. Integer to Roman(Medium)
- 13. Roman to Integer(Easy)
- 14. Longest Common Prefix(Easy)
- 15. 3Sum(Medium)