|
| 1 | +/** |
| 2 | + * [2272] Substring With Largest Variance |
| 3 | + * |
| 4 | + * 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. |
| 5 | + * Given a string s consisting of lowercase English letters only, return the largest variance possible among all substrings of s. |
| 6 | + * A substring is a contiguous sequence of characters within a string. |
| 7 | + * |
| 8 | + * Example 1: |
| 9 | + * |
| 10 | + * Input: s = "aababbb" |
| 11 | + * Output: 3 |
| 12 | + * Explanation: |
| 13 | + * All possible variances along with their respective substrings are listed below: |
| 14 | + * - Variance 0 for substrings "a", "aa", "ab", "abab", "aababb", "ba", "b", "bb", and "bbb". |
| 15 | + * - Variance 1 for substrings "aab", "aba", "abb", "aabab", "ababb", "aababbb", and "bab". |
| 16 | + * - Variance 2 for substrings "aaba", "ababbb", "abbb", and "babb". |
| 17 | + * - Variance 3 for substring "babbb". |
| 18 | + * Since the largest possible variance is 3, we return it. |
| 19 | + * |
| 20 | + * Example 2: |
| 21 | + * |
| 22 | + * Input: s = "abcde" |
| 23 | + * Output: 0 |
| 24 | + * Explanation: |
| 25 | + * No letter occurs more than once in s, so the variance of every substring is 0. |
| 26 | + * |
| 27 | + * |
| 28 | + * Constraints: |
| 29 | + * |
| 30 | + * 1 <= s.length <= 10^4 |
| 31 | + * s consists of lowercase English letters. |
| 32 | + * |
| 33 | + */ |
| 34 | +pub struct Solution {} |
| 35 | + |
| 36 | +// problem: https://leetcode.com/problems/substring-with-largest-variance/ |
| 37 | +// discuss: https://leetcode.com/problems/substring-with-largest-variance/discuss/?currentPage=1&orderBy=most_votes&query= |
| 38 | + |
| 39 | +// submission codes start here |
| 40 | + |
| 41 | +impl Solution { |
| 42 | + pub fn largest_variance(s: String) -> i32 { |
| 43 | + 0 |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +// submission codes end |
| 48 | + |
| 49 | +#[cfg(test)] |
| 50 | +mod tests { |
| 51 | + use super::*; |
| 52 | + |
| 53 | + #[test] |
| 54 | + #[ignore] |
| 55 | + fn test_2272_example_1() { |
| 56 | + let s = "aababbb".to_string(); |
| 57 | + |
| 58 | + let result = 3; |
| 59 | + |
| 60 | + assert_eq!(Solution::largest_variance(s), result); |
| 61 | + } |
| 62 | + |
| 63 | + #[test] |
| 64 | + #[ignore] |
| 65 | + fn test_2272_example_2() { |
| 66 | + let s = "abcde".to_string(); |
| 67 | + |
| 68 | + let result = 0; |
| 69 | + |
| 70 | + assert_eq!(Solution::largest_variance(s), result); |
| 71 | + } |
| 72 | +} |
0 commit comments