Skip to content

Practice Substring With Largest Variance

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#2272
LeetCode Problem

Substring With Largest Variance

Problem Statement

The variance of a string is defined as the largest difference between the number of occurrences of any 2 characters present in the string. Note the two characters may or may not be the same. Given a string s consisting of lowercase English letters only, return the largest variance possible among all substrings of s. A substring is a contiguous sequence of characters within a string.

Source: Substring With Largest Variance on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "aababbb"
Output
3

# Example 2

Input
s = "abcde"
Output
0

Constraints

1 <= s.length <= 10^4
s consists of lowercase English letters.

Related LeetCode Problems

Practice more problems similar to Substring With Largest Variance.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.