Search
⌘K

Leetcode 2272. Substring With Largest Variance

Find the maximum possible difference between counts of any two lowercase letters over all contiguous substrings of s — i.e., the largest (count(a) - count(b)) achievable in any substring. Key idea/pattern: treat each ordered pair of distinct letters and run a Kadane-like linear scan to maximize the difference while ensuring both letters appear in the substring (|s| up to 10^4).


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Your account is free and you can post anonymously if you choose.