java.lang.Object
g1101_1200.s1170_compare_strings_by_frequency_of_the_smallest_character.Solution

public class Solution extends Object
1170 - Compare Strings by Frequency of the Smallest Character.<p>Medium</p> <p>Let the function <code>f(s)</code> be the <strong>frequency of the lexicographically smallest character</strong> in a non-empty string <code>s</code>. For example, if <code>s = &quot;dcce&quot;</code> then <code>f(s) = 2</code> because the lexicographically smallest character is <code>'c'</code>, which has a frequency of 2.</p> <p>You are given an array of strings <code>words</code> and another array of query strings <code>queries</code>. For each query <code>queries[i]</code>, count the <strong>number of words</strong> in <code>words</code> such that <code>f(queries[i])</code> < <code>f(W)</code> for each <code>W</code> in <code>words</code>.</p> <p>Return <em>an integer array</em> <code>answer</code><em>, where each</em> <code>answer[i]</code> <em>is the answer to the</em> <code>i<sup>th</sup></code> <em>query</em>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> queries = [&ldquo;cbd&rdquo;], words = [&ldquo;zaaaz&rdquo;]</p> <p><strong>Output:</strong> [1]</p> <p><strong>Explanation:</strong> On the first query we have f(&ldquo;cbd&rdquo;) = 1, f(&ldquo;zaaaz&rdquo;) = 3 so f(&ldquo;cbd&rdquo;) < f(&ldquo;zaaaz&rdquo;).</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> queries = [&ldquo;bbb&rdquo;,&ldquo;cc&rdquo;], words = [&ldquo;a&rdquo;,&ldquo;aa&rdquo;,&ldquo;aaa&rdquo;,&ldquo;aaaa&rdquo;]</p> <p><strong>Output:</strong> [1,2]</p> <p><strong>Explanation:</strong> On the first query only f(&ldquo;bbb&rdquo;) < f(&ldquo;aaaa&rdquo;). On the second query both f(&ldquo;aaa&rdquo;) and f(&ldquo;aaaa&rdquo;) are both > f(&ldquo;cc&rdquo;).</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= queries.length <= 2000</code></li> <li><code>1 <= words.length <= 2000</code></li> <li><code>1 <= queries[i].length, words[i].length <= 10</code></li> <li><code>queries[i][j]</code>, <code>words[i][j]</code> consist of lowercase English letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • numSmallerByFrequency

      public int[] numSmallerByFrequency(String[] queries, String[] words)