3365. Rearrange K Substrings to Form Target String Medium

@problem@discussion
#Hash Table#String#Sorting



1/**
2 * [3365] Rearrange K Substrings to Form Target String
3 *
4 * You are given two strings s and t, both of which are anagrams of each other, and an integer k.
5 * Your task is to determine whether it is possible to split the string s into k equal-sized substrings, rearrange the substrings, and concatenate them in any order to create a new string that matches the given string t.
6 * Return true if this is possible, otherwise, return false.
7 * An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, using all the original letters exactly once.
8 * A substring is a contiguous non-empty sequence of characters within a string.
9 *  
10 * <strong class="example">Example 1:
11 * <div class="example-block">
12 * Input: <span class="example-io">s = "abcd", t = "cdab", k = 2</span>
13 * Output: <span class="example-io">true</span>
14 * Explanation:
15 * 
16 * 	Split s into 2 substrings of length 2: ["ab", "cd"].
17 * 	Rearranging these substrings as ["cd", "ab"], and then concatenating them results in "cdab", which matches t.
18 * </div>
19 * <strong class="example">Example 2:
20 * <div class="example-block">
21 * Input: <span class="example-io">s = "aabbcc", t = "bbaacc", k = 3</span>
22 * Output: <span class="example-io">true</span>
23 * Explanation:
24 * 
25 * 	Split s into 3 substrings of length 2: ["aa", "bb", "cc"].
26 * 	Rearranging these substrings as ["bb", "aa", "cc"], and then concatenating them results in "bbaacc", which matches t.
27 * </div>
28 * <strong class="example">Example 3:
29 * <div class="example-block">
30 * Input: <span class="example-io">s = "aabbcc", t = "bbaacc", k = 2</span>
31 * Output: <span class="example-io">false</span>
32 * Explanation:
33 * 
34 * 	Split s into 2 substrings of length 3: ["aab", "bcc"].
35 * 	These substrings cannot be rearranged to form t = "bbaacc", so the output is false.
36 * </div>
37 *  
38 * Constraints:
39 * 
40 * 	1 <= s.length == t.length <= 2 * 10^5
41 * 	1 <= k <= s.length
42 * 	s.length is divisible by k.
43 * 	s and t consist only of lowercase English letters.
44 * 	The input is generated such that<!-- notionvc: 53e485fc-71ce-4032-aed1-f712dd3822ba --> s and t are anagrams of each other.
45 * 
46 */
47pub struct Solution {}
48
49// problem: https://leetcode.com/problems/rearrange-k-substrings-to-form-target-string/
50// discuss: https://leetcode.com/problems/rearrange-k-substrings-to-form-target-string/discuss/?currentPage=1&orderBy=most_votes&query=
51
52// submission codes start here
53
54impl Solution {
55    pub fn is_possible_to_rearrange(s: String, t: String, k: i32) -> bool {
56        false
57    }
58}
59
60// submission codes end
61
62#[cfg(test)]
63mod tests {
64    use super::*;
65
66    #[test]
67    fn test_3365() {
68    }
69}
70


Back
© 2025 bowen.ge All Rights Reserved.