Back to photostream

Compare Strings by Frequency of the Smallest Character Leetcode Solution

The problem Compare Strings by Frequency of the Smallest Character Leetcode Solution, states that we define a function f(s) over a non-empty string s such that f(s) is equal to the frequency of the smallest character in the string. Then we are given some words and some queries. for each query, we are required to find the number of words such that f(words) > f(query_word). Then we have to return the answer for all the queries as a vector or an array. So, before diving deep into the solution, let's take a look at a few examples.

queries = , words =

 

Explanation: f("zaaaz") = 3, because the smallest character is 'a' that has a frequency equal to 3, while f("cbd") = 1. So, we have only a single word that has f(i) > f(query_word).

 

queries = , words =

 

Explanation: So, after calculation of the value of the defined function for all the given words. We find f("a") = 1, f("aa") = 2, f("aaa") = 3, f("aaaa") = 4. After evaluating the value of function for the words given in the queries, we find f("bbb") = 3, f("cc") = 2. So, then we find that for the word f("bbb"), we have a single word "aaaa" that has function value greater than 3. Similarly, for the word "cc", we have words "aaa", "aaaa" that have greater function value.

Approach

 

www.tutorialcup.com/leetcode-solutions/compare-strings-by...

19 views
0 faves
0 comments
Uploaded on September 13, 2021