3297. Count Substrings That Can Be Rearranged to Contain a String I Medium

@problem@discussion
#Hash Table#String#Sliding Window



1/**
2 * [3297] Count Substrings That Can Be Rearranged to Contain a String I
3 *
4 * You are given two strings word1 and word2.
5 * A string x is called valid if x can be rearranged to have word2 as a <span data-keyword="string-prefix">prefix</span>.
6 * Return the total number of valid <span data-keyword="substring-nonempty">substrings</span> of word1.
7 *  
8 * <strong class="example">Example 1:
9 * <div class="example-block">
10 * Input: <span class="example-io">word1 = "bcca", word2 = "abc"</span>
11 * Output: <span class="example-io">1</span>
12 * Explanation:
13 * The only valid substring is "bcca" which can be rearranged to "abcc" having "abc" as a prefix.
14 * </div>
15 * <strong class="example">Example 2:
16 * <div class="example-block">
17 * Input: <span class="example-io">word1 = "abcabc", word2 = "abc"</span>
18 * Output: <span class="example-io">10</span>
19 * Explanation:
20 * All the substrings except substrings of size 1 and size 2 are valid.
21 * </div>
22 * <strong class="example">Example 3:
23 * <div class="example-block">
24 * Input: <span class="example-io">word1 = "abcabc", word2 = "aaabc"</span>
25 * Output: <span class="example-io">0</span>
26 * </div>
27 *  
28 * Constraints:
29 * 
30 * 	1 <= word1.length <= 10^5
31 * 	1 <= word2.length <= 10^4
32 * 	word1 and word2 consist only of lowercase English letters.
33 * 
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/count-substrings-that-can-be-rearranged-to-contain-a-string-i/
38// discuss: https://leetcode.com/problems/count-substrings-that-can-be-rearranged-to-contain-a-string-i/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43    pub fn valid_substring_count(word1: String, word2: String) -> i64 {
44        
45    }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52    use super::*;
53
54    #[test]
55    fn test_3297() {
56    }
57}
58


Back
© 2025 bowen.ge All Rights Reserved.