828. Count Unique Characters of All Substrings of a Given String Hard
1/**
2 * [828] Count Unique Characters of All Substrings of a Given String
3 *
4 * Let's define a function countUniqueChars(s) that returns the number of unique characters on s.
5 *
6 * For example, calling countUniqueChars(s) if s = "LEETCODE" then "L", "T", "C", "O", "D" are the unique characters since they appear only once in s, therefore countUniqueChars(s) = 5.
7 *
8 * Given a string s, return the sum of countUniqueChars(t) where t is a substring of s. The test cases are generated such that the answer fits in a 32-bit integer.
9 * Notice that some substrings can be repeated so in this case you have to count the repeated ones too.
10 *
11 * Example 1:
12 *
13 * Input: s = "ABC"
14 * Output: 10
15 * Explanation: All possible substrings are: "A","B","C","AB","BC" and "ABC".
16 * Every substring is composed with only unique letters.
17 * Sum of lengths of all substring is 1 + 1 + 1 + 2 + 2 + 3 = 10
18 *
19 * Example 2:
20 *
21 * Input: s = "ABA"
22 * Output: 8
23 * Explanation: The same as example 1, except countUniqueChars("ABA") = 1.
24 *
25 * Example 3:
26 *
27 * Input: s = "LEETCODE"
28 * Output: 92
29 *
30 *
31 * Constraints:
32 *
33 * 1 <= s.length <= 10^5
34 * s consists of uppercase English letters only.
35 *
36 */
37pub struct Solution {}
38
39// problem: https://leetcode.com/problems/count-unique-characters-of-all-substrings-of-a-given-string/
40// discuss: https://leetcode.com/problems/count-unique-characters-of-all-substrings-of-a-given-string/discuss/?currentPage=1&orderBy=most_votes&query=
41
42// submission codes start here
43
44impl Solution {
45 pub fn unique_letter_string(s: String) -> i32 {
46 0
47 }
48}
49
50// submission codes end
51
52#[cfg(test)]
53mod tests {
54 use super::*;
55
56 #[test]
57 fn test_828() {
58 }
59}
60
Back
© 2025 bowen.ge All Rights Reserved.