2546. Apply Bitwise Operations to Make Strings Equal Medium

@problem@discussion
#String#Bit Manipulation



1/**
2 * [2546] Apply Bitwise Operations to Make Strings Equal
3 *
4 * You are given two 0-indexed binary strings s and target of the same length n. You can do the following operation on s any number of times:
5 * 
6 * 	Choose two different indices i and j where 0 <= i, j < n.
7 * 	Simultaneously, replace s[i] with (s[i] OR s[j]) and s[j] with (s[i] XOR s[j]).
8 * 
9 * For example, if s = "0110", you can choose i = 0 and j = 2, then simultaneously replace s[0] with (s[0] OR s[2] = 0 OR 1 = 1), and s[2] with (s[0] XOR s[2] = 0 XOR 1 = 1), so we will have s = "1110".
10 * Return true if you can make the string s equal to target, or false otherwise.
11 *  
12 * <strong class="example">Example 1:
13 * 
14 * Input: s = "1010", target = "0110"
15 * Output: true
16 * Explanation: We can do the following operations:
17 * - Choose i = 2 and j = 0. We have now s = "<u>0</u>0<u>1</u>0".
18 * - Choose i = 2 and j = 1. We have now s = "0<u>11</u>0".
19 * Since we can make s equal to target, we return true.
20 * 
21 * <strong class="example">Example 2:
22 * 
23 * Input: s = "11", target = "00"
24 * Output: false
25 * Explanation: It is not possible to make s equal to target with any number of operations.
26 * 
27 *  
28 * Constraints:
29 * 
30 * 	n == s.length == target.length
31 * 	2 <= n <= 10^5
32 * 	s and target consist of only the digits 0 and 1.
33 * 
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/apply-bitwise-operations-to-make-strings-equal/
38// discuss: https://leetcode.com/problems/apply-bitwise-operations-to-make-strings-equal/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43    pub fn make_strings_equal(s: String, target: String) -> bool {
44        false
45    }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52    use super::*;
53
54    #[test]
55    fn test_2546() {
56    }
57}
58


Back
© 2025 bowen.ge All Rights Reserved.