Class Solution
java.lang.Object
g2201_2300.s2272_substring_with_largest_variance.Solution
2272 - Substring With Largest Variance.<p>Hard</p>
<p>The <strong>variance</strong> of a string is defined as the largest difference between the number of occurrences of <strong>any</strong> <code>2</code> characters present in the string. Note the two characters may or may not be the same.</p>
<p>Given a string <code>s</code> consisting of lowercase English letters only, return <em>the <strong>largest variance</strong> possible among all <strong>substrings</strong> of</em> <code>s</code>.</p>
<p>A <strong>substring</strong> is a contiguous sequence of characters within a string.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> s = “aababbb”</p>
<p><strong>Output:</strong> 3</p>
<p><strong>Explanation:</strong> All possible variances along with their respective substrings are listed below:</p>
<ul>
<li>
<p>Variance 0 for substrings “a”, “aa”, “ab”, “abab”, “aababb”, “ba”, “b”, “bb”, and “bbb”.</p>
</li>
<li>
<p>Variance 1 for substrings “aab”, “aba”, “abb”, “aabab”, “ababb”, “aababbb”, and “bab”.</p>
</li>
<li>
<p>Variance 2 for substrings “aaba”, “ababbb”, “abbb”, and “babb”.</p>
</li>
<li>
<p>Variance 3 for substring “babbb”.</p>
</li>
</ul>
<p>Since the largest possible variance is 3, we return it.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> s = “abcde”</p>
<p><strong>Output:</strong> 0</p>
<p><strong>Explanation:</strong> No letter occurs more than once in s, so the variance of every substring is 0.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= s.length <= 10<sup>4</sup></code></li>
<li><code>s</code> consists of lowercase English letters.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
largestVariance
-