#1170
Compare Strings by Frequency of the Smallest Character
specialist · 730 · lc medium +31 · verified · 63.2% accepted · 752 likes · top 65%
Description
Define function f(s) as the count of occurrences of the lexicographically smallest character in the non-empty string s. For example, if s = "dcce" then f(s) = 2 since 'c' is the smallest character and appears twice.
You receive an array words and an array of query strings queries. For each queries[i], count how many words W in words satisfy f(queries[i]) < f(W).
Return an integer array answer where answer[i] holds the result for the ith query.
Example 1:
Input: queries = ["cbd"], words = ["zaaaz"]
Output: [1]
Explanation: On the first query we have f("cbd") = 1, f("zaaaz") = 3 so f("cbd") < f("zaaaz").
Example 2:
Input: queries = ["bbb","cc"], words = ["a","aa","aaa","aaaa"]
Output: [1,2]
Explanation: On the first query only f("bbb") < f("aaaa"). On the second query both f("aaa") and f("aaaa") are both > f("cc").
Code
1
2
3