Problem Statement
The weight of a string S can be computed as follows: for each letter that occurs at least once in S, its leftmost and rightmost occurrences L and R are found and the weight is increased by R-L.
For example, if S="ABCACAZ", the weight of S is (5-0) + (1-1) + (4-2) + (6-6) = 7. (The leftmost occurrence of 'A' is at the index L=0, the rightmost one is at R=5, so 'A' contributes 5-0 = 5 to the weight of S. The only 'B' contributes 0, the pair of 'C's adds 2, and the only 'Z' adds 0.)
You are given a
Definition
- Class:
- StringWeightDiv2
- Method:
- countMinimums
- Parameters:
- int
- Returns:
- int
- Method signature:
- int countMinimums(int L)
- (be sure your method is public)
Constraints
- L will be between 1 and 1000, inclusive.
Examples
1
Returns: 26
Any string of length 1 has weight equal to 0.
2
Returns: 650
We can divide strings of length 2 into two classes: the strings with distinct first and second letter, and the strings with two equal letters. The strings composed of two equal letters have weight 1. All the other strings have weight 0. Thus, the number of strings of minimum weight is 26*26-26=650.
50
Returns: 488801539
3
Returns: 15600
4
Returns: 358800
13
Returns: 949597241
20
Returns: 608487724
26
Returns: 111157338
27
Returns: 890090770
35
Returns: 939243459
49
Returns: 116964018
81
Returns: 903534367
100
Returns: 997628957
256
Returns: 905751828
512
Returns: 958139959
666
Returns: 995360682
782
Returns: 222116359
981
Returns: 725153921
998
Returns: 293776719
999
Returns: 849115283
1000
Returns: 227172651
117
Returns: 941935388
550
Returns: 511641044
260
Returns: 56914315