← Bank of America Interview Insights

Bank of America·Data Scientist·Online Assessment (OA)·Intermediate

Intermediate
May 2026

Summary

Got an online assessment for a Data Scientist role at Bank of America. One coding problem, string manipulation with a greedy twist. Pretty standard OA vibe but the problem had a bit more math to it than I expected.

Questions Asked (1)

Q1

Given a string, assign distinct integer values 1 through 26 to each letter of the alphabet (case-insensitive, ignoring punctuation and spaces). The beauty of the string is the sum of each letter's assigned value multiplied by how many times it appears. Write a solution that computes the maximum possible beauty for each input string.

Algorithms & Data Structures
Author's notes

The greedy insight is pretty straightforward once you see it: sort letters by frequency descending, then assign the highest beauty values to the most frequent ones.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the problem: we need to assign values 1-26 to letters to maximize the sum of value × frequency. The optimal strategy is to assign the highest value (26) to the most frequent letter, the next highest (25) to the second most frequent, and so on. So, count the frequency of each letter (case-insensitive, ignoring non-letters), sort frequencies in descending order, and compute the weighted sum.

Pro tip: In a data science interview, emphasize that this is a greedy algorithm that is provably optimal by the rearrangement inequality. Also, mention that you would validate with edge cases like empty strings or strings with only punctuation.

1. Clarify requirements and constraints

Confirm that letters are case-insensitive, punctuation and spaces are ignored, and values 1-26 are assigned to letters a-z. Ask about input size and character set to ensure efficiency.

2. Count letter frequencies

Iterate through the string, convert each character to lowercase, and if it's a letter, increment its count in a frequency array or hash map. Ignore non-letter characters.

3. Sort frequencies in descending order

Extract the frequency counts and sort them from highest to lowest. This ensures the most frequent letters get the highest values.

4. Assign values and compute beauty

Starting with value 26, multiply each frequency by the current value, sum the products, and decrement the value for each subsequent frequency. Return the total sum.

5. Analyze complexity and test edge cases

State that time complexity is O(n + k log k) where n is string length and k is number of distinct letters (≤26), so effectively O(n). Test with empty string, all same letter, all distinct letters, and mixed case/punctuation.

Key Points to Mention

  • Greedy approach: assign highest values to highest frequencies
  • Proof of optimality via rearrangement inequality
  • Case-insensitive handling and ignoring non-letter characters
  • Time and space complexity analysis
  • Edge cases: empty string, no letters, all letters same, maximum distinct letters
  • Potential for using counting sort since frequencies are bounded by string length

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.