2683. Neighboring Bitwise XOR Medium
1/**
2 * [2683] Neighboring Bitwise XOR
3 *
4 * A 0-indexed array derived with length n is derived by computing the bitwise XOR (⊕) of adjacent values in a binary array original of length n.
5 * Specifically, for each index i in the range [0, n - 1]:
6 *
7 * If i = n - 1, then derived[i] = original[i] ⊕ original[0].
8 * Otherwise, derived[i] = original[i] ⊕ original[i + 1].
9 *
10 * Given an array derived, your task is to determine whether there exists a valid binary array original that could have formed derived.
11 * Return true if such an array exists or false otherwise.
12 *
13 * A binary array is an array containing only 0's and 1's
14 *
15 *
16 * <strong class="example">Example 1:
17 *
18 * Input: derived = [1,1,0]
19 * Output: true
20 * Explanation: A valid original array that gives derived is [0,1,0].
21 * derived[0] = original[0] ⊕ original[1] = 0 ⊕ 1 = 1
22 * derived[1] = original[1] ⊕ original[2] = 1 ⊕ 0 = 1
23 * derived[2] = original[2] ⊕ original[0] = 0 ⊕ 0 = 0
24 *
25 * <strong class="example">Example 2:
26 *
27 * Input: derived = [1,1]
28 * Output: true
29 * Explanation: A valid original array that gives derived is [0,1].
30 * derived[0] = original[0] ⊕ original[1] = 1
31 * derived[1] = original[1] ⊕ original[0] = 1
32 *
33 * <strong class="example">Example 3:
34 *
35 * Input: derived = [1,0]
36 * Output: false
37 * Explanation: There is no valid original array that gives derived.
38 *
39 *
40 * Constraints:
41 *
42 * n == derived.length
43 * 1 <= n <= 10^5
44 * The values in derived are either 0's or 1's
45 *
46 */
47pub struct Solution {}
48
49// problem: https://leetcode.com/problems/neighboring-bitwise-xor/
50// discuss: https://leetcode.com/problems/neighboring-bitwise-xor/discuss/?currentPage=1&orderBy=most_votes&query=
51
52// submission codes start here
53
54impl Solution {
55 pub fn does_valid_array_exist(derived: Vec<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_2683() {
68 }
69}
70
Back
© 2025 bowen.ge All Rights Reserved.