Compare Strings by Frequency of the Smallest Character

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
from typing import List

class Solution:
    def numSmallerByFrequency(self, queries: List[str], words: List[str]) -> List[int]:
        def f(s: str) -> int:
            return s.count(min(s))

        words_freq = [f(word) for word in words]
        words_freq.sort()

        result = []
        for query in queries:
            count = 0
            query_freq = f(query)
            for word_freq in words_freq:
                if query_freq < word_freq:
                    count += 1
            result.append(count)

        return result