Katkat

Compute maximum beauty of a string

Bank of AmericaData Scientist · Online Assessment

Last updated

This question evaluates skills in string manipulation, frequency analysis, and optimization of weighted sums, focusing on assigning distinct values to characters to maximize an aggregate metric.

Given a string s, define the beauty of each letter a–z as a distinct integer between 1 and 26, case-insensitive. The beauty of a string is the sum over letters of (letter beauty × its frequency). Ignore punctuation and spaces. For each input line containing a string, compute and print the maximum possible beauty by choosing an assignment of beauties to letters that maximizes the sum. Examples: Input "ABbCCC" → 152; Input "Ignore punctuation, please :)" → 491.