Problem Β· String

Find Maximum Maxima Count 🍊

● MediumAmazonFULLTIMEOA
See Amazon hiring insights

Amazon has a string of categories of items purchased by a particular customer, each represented as a lowercase English letter. To analyze customer behavior, we define a metric called the MaximaCount of a category. It is the number of indices where the frequency of some category c is maximum among all categories present in the prefix.

More elaboratively, MaximaCount of character, char, representing a category is defined as the number of indices i, such that the frequency of char is maximal in the prefix of the string up to the index i.

Given the string categories, find the maximum MaximaCount among all the categories.

Function Description

Complete the function findMaximumMaximaCount in the editor.

findMaximumMaximaCount has the following parameter:

  1. string categories: the given string

Returns

int: the maximum MaximaCount

♫⋆qβ™ͺ πŸ³π“‚ƒ π“ˆ’π“ΈΛšβ™¬ ゚1013rd thank you on the way to spike! ༊·˚

Examples
01 Β· Example 1
categories = "bccaaacb"
return = 6
Example 1 illustration
From the above table (assuming 1-based indexing):
  • MaximaCount of a = 4 at indices 5, 6, 7, 8
  • MaximaCount of b = 2 at indices 1, 2
  • MaximaCount of c = 6 at indices 2, 3, 4, 5, 7, 8
  • Thus the maximum MaximaCount is 6 for the character c.
    02 Β· Example 2
    categories = "zzzz"
    return = 4
    Since all characters in the string are equal, the maximum MaximaCount is 4 for the character z.
    03 Β· Example 3
    categories = "adbcbcbcc"
    return = 6
    There are four different categories: [a,b,c,d] For a, we have a MaximaCount equal to 4 at indices 1, 2, 3, 4. For b, we have a MaximaCount equal to 6 at indices 3, 4, 5, 6, 7, and 8. For c, we have a MaximaCount equal to 4 at indices 4, 6, 8, and 9. For d, we have a MaximaCount equal to 4 at indices 1, 2, 3, 4.
    Constraints
    • The length(categories) <= 10^5
    • The string categories consists of lowercase English characters only.
    More Amazon problems
    drafts saved locally
    public int findMaximumMaximaCount(String categories) {
      // write your code here
    }
    
    categories"bccaaacb"
    expected6
    sign in to submit