1170. Compare Strings by Frequency of the Smallest Character Medium

@problem@discussion
#Array#Hash Table#String#Binary Search#Sorting



1/**
2 * [1170] Compare Strings by Frequency of the Smallest Character
3 *
4 * Let the function f(s) be the frequency of the lexicographically smallest character in a non-empty string s. For example, if s = "dcce" then f(s) = 2 because the lexicographically smallest character is 'c', which has a frequency of 2.
5 * You are given an array of strings words and another array of query strings queries. For each query queries[i], count the number of words in words such that f(queries[i]) < f(W) for each W in words.
6 * Return an integer array answer, where each answer[i] is the answer to the i^th query.
7 *  
8 * Example 1:
9 * 
10 * Input: queries = ["cbd"], words = ["zaaaz"]
11 * Output: [1]
12 * Explanation: On the first query we have f("cbd") = 1, f("zaaaz") = 3 so f("cbd") < f("zaaaz").
13 * 
14 * Example 2:
15 * 
16 * Input: queries = ["bbb","cc"], words = ["a","aa","aaa","aaaa"]
17 * Output: [1,2]
18 * Explanation: On the first query only f("bbb") < f("aaaa"). On the second query both f("aaa") and f("aaaa") are both > f("cc").
19 * 
20 *  
21 * Constraints:
22 * 
23 * 	1 <= queries.length <= 2000
24 * 	1 <= words.length <= 2000
25 * 	1 <= queries[i].length, words[i].length <= 10
26 * 	queries[i][j], words[i][j] consist of lowercase English letters.
27 * 
28 */
29pub struct Solution {}
30
31// problem: https://leetcode.com/problems/compare-strings-by-frequency-of-the-smallest-character/
32// discuss: https://leetcode.com/problems/compare-strings-by-frequency-of-the-smallest-character/discuss/?currentPage=1&orderBy=most_votes&query=
33
34// submission codes start here
35
36impl Solution {
37    pub fn num_smaller_by_frequency(queries: Vec<String>, words: Vec<String>) -> Vec<i32> {
38        vec![]
39    }
40}
41
42// submission codes end
43
44#[cfg(test)]
45mod tests {
46    use super::*;
47
48    #[test]
49    fn test_1170() {
50    }
51}
52


Back
© 2025 bowen.ge All Rights Reserved.