1616. Split Two Strings to Make Palindrome Medium
1/**
2 * [1616] Split Two Strings to Make Palindrome
3 *
4 * You are given two strings a and b of the same length. Choose an index and split both strings at the same index, splitting a into two strings: aprefix and asuffix where a = aprefix + asuffix, and splitting b into two strings: bprefix and bsuffix where b = bprefix + bsuffix. Check if aprefix + bsuffix or bprefix + asuffix forms a palindrome.
5 * When you split a string s into sprefix and ssuffix, either ssuffix or sprefix is allowed to be empty. For example, if s = "abc", then "" + "abc", "a" + "bc", "ab" + "c" , and "abc" + "" are valid splits.
6 * Return true if it is possible to form a palindrome string, otherwise return false.
7 * Notice that x + y denotes the concatenation of strings x and y.
8 *
9 * Example 1:
10 *
11 * Input: a = "x", b = "y"
12 * Output: true
13 * Explaination: If either a or b are palindromes the answer is true since you can split in the following way:
14 * aprefix = "", asuffix = "x"
15 * bprefix = "", bsuffix = "y"
16 * Then, aprefix + bsuffix = "" + "y" = "y", which is a palindrome.
17 *
18 * Example 2:
19 *
20 * Input: a = "xbdef", b = "xecab"
21 * Output: false
22 *
23 * Example 3:
24 *
25 * Input: a = "ulacfd", b = "jizalu"
26 * Output: true
27 * Explaination: Split them at index 3:
28 * aprefix = "ula", asuffix = "cfd"
29 * bprefix = "jiz", bsuffix = "alu"
30 * Then, aprefix + bsuffix = "ula" + "alu" = "ulaalu", which is a palindrome.
31 *
32 *
33 * Constraints:
34 *
35 * 1 <= a.length, b.length <= 10^5
36 * a.length == b.length
37 * a and b consist of lowercase English letters
38 *
39 */
40pub struct Solution {}
41
42// problem: https://leetcode.com/problems/split-two-strings-to-make-palindrome/
43// discuss: https://leetcode.com/problems/split-two-strings-to-make-palindrome/discuss/?currentPage=1&orderBy=most_votes&query=
44
45// submission codes start here
46
47impl Solution {
48 pub fn check_palindrome_formation(a: String, b: String) -> bool {
49 false
50 }
51}
52
53// submission codes end
54
55#[cfg(test)]
56mod tests {
57 use super::*;
58
59 #[test]
60 fn test_1616() {
61 }
62}
63
Back
© 2025 bowen.ge All Rights Reserved.