2678. Number of Senior Citizens
Approach
Parse age from chars at index 11-12 of each detail string; count those > 60.
Key Techniques
Array problems involve manipulating elements stored in a contiguous block of memory. Key techniques include two-pointer traversal, prefix sums, sliding windows, and in-place partitioning. In C#, arrays are zero-indexed and fixed in size — use List<T> when you need dynamic resizing.
String problems range from simple character counting to complex pattern matching. Common approaches include two pointers, sliding window, prefix hashing, and the KMP algorithm. In C#, strings are immutable — use StringBuilder for efficient concatenation inside loops.
Simulation problems require implementing the described process step by step. Focus on correctly handling edge cases and state transitions. Common in geometry, game problems, and string manipulation. Optimize only if the naive simulation exceeds the time limit.
// 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();
}
}