TopCoder problem "ArrayHash" used in SRM 238 (Division II Level One)



Problem Statement

    You will be given a String[] input. The value of each character in input is computed as follows:
   Value = (Alphabet Position) + (Element of input) + (Position in Element) 
All positions are 0-based. 'A' has alphabet position 0, 'B' has alphabet position 1, ... The returned hash is the sum of all character values in input. For example, if
input = {"CBA",
         "DDD"}
then each character value would be computed as follows:
2 =   2 + 0 + 0   :  'C' in element 0 position 0
2 =   1 + 0 + 1   :  'B' in element 0 position 1
2 =   0 + 0 + 2   :  'A' in element 0 position 2
4  =  3 + 1 + 0   :  'D' in element 1 position 0
5  =  3 + 1 + 1   :  'D' in element 1 position 1
6  =  3 + 1 + 2   :  'D' in element 1 position 2
The final hash would be 2+2+2+4+5+6 = 21.
 

Definition

    
Class:ArrayHash
Method:getHash
Parameters:String[]
Returns:int
Method signature:int getHash(String[] input)
(be sure your method is public)
    
 

Constraints

-input will contain between 1 and 50 elements inclusive.
-Each character in each element of input will be a capital letter ('A'-'Z').
-Each element of input will contain between 1 and 50 characters inclusive.
-Each element of input will contain the same number of characters.
 

Examples

0)
    
{"CBA",
 "DDD"}
Returns: 21
From the problem statement.
1)
    
{"Z"}
Returns: 25
A very small example.
2)
    
{"A",
 "B",
 "C",
 "D",
 "E",
 "F"}
Returns: 30
Tall and narrow.
3)
    
{"ABCDEFGHIJKLMNOPQRSTUVWXYZ",
 "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
 "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
 "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
 "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"}
Returns: 4290
4)
    
{"ZZZZZZZZZZ"}
Returns: 295

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=4503

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=6537&pm=4503

Writer:

AdminBrett

Testers:

PabloGilberto , lbackstrom , Olexiy

Problem categories:

Brute Force, Simple Search, Iteration