Maximum String Beauty
Updated
Problem statement
Given a string s, give each of the 26 English letters a different beauty value from 1 to 26 so that the beauty of s is as large as possible, and return that largest beauty.
The beauty of s is the sum of the beauty values of all its letters. Upper and lower case forms of a letter are the same letter and share one value. Characters that are not letters add nothing.
Function
maxBeauty(s: String) → intExamples
Example 1
s = "Hello"return = 124l appears twice and gets 26. h, e and o appear once and get 25, 24 and 23. 2 * 26 + 25 + 24 + 23 = 124.
Example 2
s = "aAbB, ab!"return = 153Ignoring case, a and b each appear 3 times; the comma, space and ! add nothing. One gets 26 and the other 25: 3 * 26 + 3 * 25 = 153.
Example 3
s = "2024!"return = 0There are no letters, so the beauty is 0.
Constraints
1 <= s.length <= 10^4sconsists of English letters, digits, spaces and the characters. , ! ? : ; ' ( ) -
More Bank of America Online Assessment questions
- Return Exact Cash Register ChangeOA · Seen Aug 2026
- Sum Skipping Multiples of 7OA · Seen Nov 2025
- Wildcard Substring MatchOA · Seen Nov 2025
- Merge Point of Two Linked ListsOA · Seen Oct 2023
- Remove Duplicates from a ListOA · Seen Oct 2023
- Pairs with Target Sum in a Sorted ArrayOA · Seen Oct 2023
- Count Level-Order Traversals of a TreeOA · Seen Sep 2023
- Count Set BitsOA · Seen Sep 2023
- Count Pairs with Sum KOA · Seen Jun 2023
- Letter Pattern SumOA · Seen Sep 2022
Similar questions at other companies
- Maximize Palindromic WordsSquarepoint Capital · OASquarepoint Capital interview questions
- Count User Mentions in Chat MessagesRamp · OARamp interview questions
- Blood Type Inheritance: Possible Parent GenotypesAbridge · OAAbridge interview questions
- Count Repeated Request IDs (Data Science OA)McKinsey & Company · OAMcKinsey & Company interview questions
- Minimum Operations to Reduce a Transaction LedgerVisa · OAVisa interview questions
- Flat JSON Value DifferencesChubb · OAChubb interview questions
- Get Search ResultsJP Morgan Chase · OAJP Morgan Chase interview questions
- Lexicographic Word FrequenciesUpstart · OAUpstart interview questions
- Email Log Processing, Grouping, and SortingStripe · OAStripe interview questions
- Most Frequent CharacterMicrosoft · OAMicrosoft interview questions