Google | Phone Screen | Most frequent character in string grouped by characters
Anonymous User
4634

You are given a string that is grouped together by characters. For example a sample input could be: "hhzzzzaaa", and we need to output the most frequently occuring character so for our example we would output 'z'.

I was only asked this question on the phone screen.

Brute Force:

  1. Keep a Character -> Integer map to count the frequency of each character.
  2. Return the max count character that the end
  3. Linear time and space
  4. Disadvantage is that we are not taking into consideration that the characters are grouped together...

Optimization 1:

  1. Since the characters are kept in groups, we need to find the index where the character changes.
  2. To get the count of a specific character, we need to subtract i - pivot.
  3. Linear Time and Constant Space

I thought Linear time and constant space was the optimal solution, but it turns out the interviewer wanted me to optimize further into Log N time and constant space. This is where I struggled. After a hint I was able to code out the binary search solution.

Still waiting for the results. How do you think I did?
Personally I feel like I could have passed, but on the other hand I feel bad for not getting the binary search solution without a hint...
The interviewer had a poker face the entire time. I could not deduce anything about my interview performance..

Comments (10)