3849. Maximum Bitwise XOR After Rearrangement Medium

@problem@discussion
#String#Greedy#Bit Manipulation



1/**
2 * [3849] Maximum Bitwise XOR After Rearrangement
3 *
4 * You are given two binary strings s and t​​​​​​​, each of length n.
5 * You may rearrange the characters of t in any order, but s must remain unchanged.
6 * Return a binary string of length n representing the maximum integer value obtainable by taking the bitwise XOR of s and rearranged t.
7 *  
8 * <strong class="example">Example 1:
9 * <div class="example-block">
10 * Input: <span class="example-io">s = "101", t = "011"</span>
11 * Output: <span class="example-io">"110"</span>
12 * Explanation:
13 * 
14 * 	One optimal rearrangement of t is "011".
15 * 	The bitwise XOR of s and rearranged t is "101" XOR "011" = "110", which is the maximum possible.
16 * </div>
17 * <strong class="example">Example 2:
18 * <div class="example-block">
19 * Input: <span class="example-io">s = "0110", t = "1110"</span>
20 * Output: <span class="example-io">"1101"</span>
21 * Explanation:
22 * 
23 * 	One optimal rearrangement of t is "1011".
24 * 	The bitwise XOR of s and rearranged t is "0110" XOR "1011" = "1101", which is the maximum possible.
25 * </div>
26 * <strong class="example">Example 3:
27 * <div class="example-block">
28 * Input: <span class="example-io">s = "0101", t = "1001"</span>
29 * Output: <span class="example-io">"1111"</span>
30 * Explanation:
31 * 
32 * 	One optimal rearrangement of t is "1010".
33 * 	The bitwise XOR of s and rearranged t is "0101" XOR "1010" = "1111", which is the maximum possible.
34 * </div>
35 *  
36 * Constraints:
37 * 
38 * 	1 <= n == s.length == t.length <= 2 * 10^5
39 * 	s[i] and t[i] are either '0' or '1'.
40 * 
41 */
42pub struct Solution {}
43
44// problem: https://leetcode.com/problems/maximum-bitwise-xor-after-rearrangement/
45// discuss: https://leetcode.com/problems/maximum-bitwise-xor-after-rearrangement/discuss/?currentPage=1&orderBy=most_votes&query=
46
47// submission codes start here
48
49impl Solution {
50    pub fn maximum_xor(s: String, t: String) -> String {
51        String::new()
52    }
53}
54
55// submission codes end
56
57#[cfg(test)]
58mod tests {
59    use super::*;
60
61    #[test]
62    fn test_3849() {
63    }
64}
65

Back
© 2026 bowen.ge All Rights Reserved.