TopcoderArchiveVisit Topcoder
Archive
Algorithm problem

SecretSum

Problem statement, definition, constraints, and public examples.

Problem Statement

We can substitute each digit of a number with a unique letter from 'A' to 'Z'. This way we can write groups of numbers in a single representation. For example "ABA" can represent any of the following: 101, 151, 343, 767, 929. However, "ABA" cannot mean 555 because each letter must stand for a distinct digit. Furthermore, numbers cannot begin with 0 and thus 'A' cannot be replaced by 0.

Given two such representations num1 and num2 and the result of their summation return the total number of possible combinations of numbers for which the equation holds. If no combinations are possible then return 0.

Definition

Class:
SecretSum
Method:
countPossible
Parameters:
String, String, String
Returns:
int
Method signature:
int countPossible(String num1, String num2, String result)
(be sure your method is public)

Constraints

  • num1, num2, and result will each contain exactly 3 uppercase letters ('A' - 'Z').

Examples

  1. "AAA"
    "AAA"
    "BBB"
    Returns: 4
    We can have the following 4 sums: 111 + 111 = 222 222 + 222 = 444 333 + 333 = 666 444 + 444 = 888
  2. "ABC"
    "ABA"
    "ACC"
    Returns: 0
    Leading zeroes are not allowed.
  3. "AAA"
    "CDD"
    "BAA"
    Returns: 32
  4. "GOO"
    "GLE"
    "ABC"
    Returns: 249
Back to all problems