Compute maximum beauty of a string
Problem Description
Given an input string, s, we need to calculate its "maximum beauty".
The beauty of individual letters (a-z, case-insensitive) is defined as a distinct integer value between 1 and 26. Each of the 26 unique letters must be assigned a unique beauty score from this range.
The beauty of a string is computed as the sum of (letter beauty × its frequency) for all letters present in the string. Punctuation and spaces should be ignored when calculating letter frequencies.
The objective is to determine the maximum possible beauty for the given string s by optimally assigning beauty scores to the letters.
Examples
-
Input: "ABbCCC" Output: 152
-
Input: "Ignore punctuation, please :)" Output: 491
AI interview prep
Core dilemma
Optimally assigning a fixed set of weighted values (beauty scores) to a variable set of items (letter frequencies) to maximize their sum, given constraints on uniqueness and range.
2 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Compute maximum beauty of a string
Problem Description
Given an input string, s, we need to calculate its "maximum beauty".
The beauty of individual letters (a-z, case-insensitive) is defined as a distinct integer value between 1 and 26. Each of the 26 unique letters must be assigned a unique beauty score from this range.
The beauty of a string is computed as the sum of (letter beauty × its frequency) for all letters present in the string. Punctuation and spaces should be ignored when calculating letter frequencies.
The objective is to determine the maximum possible beauty for the given string s by optimally assigning beauty scores to the letters.
Examples
-
Input: "ABbCCC" Output: 152
-
Input: "Ignore punctuation, please :)" Output: 491