TopCoder problem "BirthNumbersValidator" used in SRM 333 (Division I Level One , Division II Level Two)

Problem Statement


In Slovakia, every person is assigned a unique 10-digit string when he is born. This string is known as the birth number of the respective person.

The birth number has the form "YYMMDDCCCC", where:

  • YY are the last two digits of the year.
  • For males, MM is a two-digit number of the month, i.e., a number between 01 and 12, inclusive.

    For females, MM is the number of the month increased by 50, i.e., a number between 51 and 62, inclusive.
  • DD is a two digit number of the day in the month.
  • CCCC are four arbitrary digits that are used both as a checksum and as a way to distinguish between different people born on the same day.

    The checksum property works as follows: the digits CCCC must be chosen in such a way that the entire 10-digit number is divisible by eleven (11).

For example, the strings "8104121234" and "8154121239" represent valid birth numbers.

(The first person is male, the second one female. Both of them are born on April 12th, ??81.)

The strings "8134120005", "8102310007", and "8104121235" are not valid birth numbers.

(In the first case, "34" can not be a valid month. In the second case, the day number is wrong, as the second month has less than 31 days. In the third case, the date is valid but the number is not divisible by 11.)

You will be given a String[] test containing several ten-digit strings. Write a method that will return a String[] with the same number of elements. If the i-th element of test is a valid birth number the i-th element of the return value shall be "YES", otherwise the i-th element of the return value shall be "NO". When checking whether the date is valid, assume that the year when the person was born is between 1907 and 2006, inclusive.



Method signature:String[] validate(String[] test)
(be sure your method is public)


-The number of days in each month of a non-leap year (from 1 to 12): 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31.
-Leap years have 29 days in the second month.
-A year is a leap year if either (the year is divisible by 400) or (the year is divisible by 4, but not by 100).

For example, 2000 and 2004 are leap years, 1900 and 1947 are not.


-test will contain between 1 and 50 elements, inclusive.
-Each element of test will contain exactly 10 characters.
-Each element of test will contain only digits ('0'-'9').


Returns: {"YES" }
The first example from the problem statement.
Returns: {"YES" }
The second example from the problem statement.
Returns: {"NO" }
The third example from the problem statement.
Returns: {"NO", "NO" }
The last two examples from the problem statement.
Returns: {"YES" }
Note that leading zeros may occur in a valid birth number.

Problem url:

Problem stats url:




PabloGilberto , brett1479 , Olexiy , Mike Mirzayanov

Problem categories:

Simple Math