TopcoderArchiveVisit Topcoder
TCO27 Mar 2012
TCO12 Round 1C

PasswordXGuessing

Problem statement, definition, constraints, and public examples.

Problem Statement

Ms. Ciel loves rabbits. She has a large special cage for her rabbits. The special cage is protected by a secret password consisting of exactly X digits. Each digit of her password is one of '0'-'9'. (It is possible that the password starts with a '0'.)

There are N friends who want to guess the password. Each friend make a guess consisting of exactly X digits. This is given in String[] guesses that contains N elements, where guesses[i] is the guess of the i-th friend. The friends are so lucky that after they make their guesses, Ms. Ciel tells them that each person guessed the password correctly, except for exactly one digit.

You are given the String[] guesses. Return the number of different passwords that have the above property (i.e., differ from each element of guesses in exactly one digit). Note that it is possible that no such password exists. In such case, return 0.

Definition

Class:
PasswordXGuessing
Method:
howMany
Parameters:
String[]
Returns:
long
Method signature:
long howMany(String[] guesses)
(be sure your method is public)

Notes

  • The result is guaranteed to fit in a 64-bit signed integer data type.

Constraints

  • guesses will contain between 1 and 50 elements, inclusive.
  • Each element of guesses will contain between 1 and 50 characters, inclusive.
  • All elements of guesses will contain the same number of characters.
  • Each character of each element of guesses will be one of '0'-'9'.

Examples

  1. {"58", "47"}
    Returns: 2
    The two possible passwords are "57" and "48".
  2. {"539", "540", "541"}
    Returns: 1
    The only possible password is "549".
  3. {"12", "34", "56", "78"}
    Returns: 0
    There is no possible password. Ms. Ciel must have forgotten her own password.
  4. {"2", "3", "5"}
    Returns: 7
  5. {"4747", "4747", "4747", "4747"}
    Returns: 36
Back to all problems