Magicsheet logo

Number of Senior Citizens

Easy
12.5%
Updated 8/1/2025

Asked by 3 Companies

Number of Senior Citizens

What is this problem about?

The Number of Senior Citizens problem gives you a list of passenger details as strings in a fixed format. Extract each passenger's age from the string and count how many passengers are strictly older than 60 years. This easy coding problem tests string indexing and character-to-integer conversion.

Why is this asked in interviews?

Meta, Google, and Bloomberg ask this easy problem to quickly verify string parsing skills — specifically, extracting a substring from a fixed-format string and comparing it numerically. The array and string interview pattern is demonstrated at a fundamental level.

Algorithmic pattern used

Fixed-position substring extraction. Each passenger string has the age at a known position (e.g., indices 11-12 in a fixed-format string). Extract int(details[11:13]) for each passenger and count those > 60.

Example explanation

details = ["7868190130M7522","5303914400F9211"].

  • Passenger 1: age = int("75") = 75 > 60 ✓.
  • Passenger 2: age = int("92") = 92 > 60 ✓. Count = 2.

Common mistakes candidates make

  • Off-by-one in the substring indices (must know exact position of age in the format).
  • Using >= 60 instead of > 60 (problem says strictly older than 60).
  • Comparing as strings instead of converting to integer.
  • Not reading the format specification carefully.

Interview preparation tip

Fixed-format string parsing problems require reading the specification exactly. Always draw out the character positions before coding: "position 0-1 = phone type, 2-10 = phone number, 11-12 = age..." etc. Extract the relevant substring and convert to the appropriate type. Easy problems like this are accuracy tests — wrong indexing or wrong comparison operator means a wrong answer despite correct logic. Slow down and verify the format specification.

Similar Questions