Skip to content

Commit 8acdc16

Browse files
committed
Add daily 2683. Neighboring Bitwise XOR
1 parent 06232af commit 8acdc16

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ go test ./easy/0001_two_sum
3939
| [3223](https://leetcode.com/problems/minimum-length-of-string-after-operations/description/?envType=daily-question&envId=2025-01-13) | [Minimum Length of String After Operations](/medium/2116_check_if_a_parentheses_string_can_be_valid) | Medium | _`HashTable`_ _`String`_ _`Counting`_ |
4040
| [2657](https://leetcode.com/problems/find-the-prefix-common-array-of-two-arrays/description/?envType=daily-question&envId=2025-01-14) | [Find the Prefix Common Array of Two Arrays](/medium/2657_find_the_prefix_common_array_of_two_arrays) | Medium | _`HashTable`_ _`Array`_ |
4141
| [2429](https://leetcode.com/problems/minimize-xor/description/?envType=daily-question&envId=2025-01-15) | [Minimize XOR](/medium/2429_minimize_XOR) | Medium | _`Bit Manipulation`_ |
42-
| [2425](https://leetcode.com/problems/bitwise-xor-of-all-pairings/description/?envType=daily-question&envId=2025-01-16) | [Bitwise XOR of All Pairings](/medium/2429_minimize_XOR) | Medium | _`Bit Manipulation`_ _`Brain Teaser`_ |
42+
| [2425](https://leetcode.com/problems/neighboring-bitwise-xor/description/) | [Bitwise XOR of All Pairings](/medium/2429_minimize_XOR) | Medium | _`Bit Manipulation`_ _`Brain Teaser`_ |
43+
| [2683](https://leetcode.com/problems/bitwise-xor-of-all-pairings/description/?envType=daily-question&envId=2025-01-16) | [Neighboring Bitwise XOR](/medium/2683_neighboring_bitwise_XOR) | Medium | _`Bit Manipulation`_ _`Array`_ |
4344
| [1368](https://leetcode.com/problems/minimum-cost-to-make-at-least-one-valid-path-in-a-grid/?envType=daily-question&envId=2025-01-18) | [Minimum Cost to Make at Least One Valid Path in a Grid](/hard/1368_minimum_cost_to_make_at_least_one_valid_path_in_a_grid) | Hard | _`Breadth First Search`_ _`Graph`_ `Heap(Priority Queue)` _`Matrix`_ _`Shortest Path`_ _`Array`_ |
4445

4546
## License 🪪
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package neighboring_bitwise_XOR
2+
3+
4+
func doesValidArrayExist(derived []int) bool {
5+
original := []int{0}
6+
for i := 0; i < len(derived); i++ {
7+
original = append(original, derived[i]^original[i])
8+
}
9+
checkForZero := original[0] == original[len(original)-1]
10+
11+
original = []int{1}
12+
for i := 0; i < len(derived); i++ {
13+
original = append(original, derived[i]^original[i])
14+
}
15+
checkForOne := original[0] == original[len(original)-1]
16+
17+
return checkForZero || checkForOne
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package neighboring_bitwise_XOR
2+
3+
import "testing"
4+
5+
6+
func TestDoesValidArrayExist(t *testing.T) {
7+
tests := []struct {
8+
name string
9+
derived []int
10+
expectedResult bool
11+
} {
12+
{
13+
name: "Test Case 1",
14+
derived: []int{1,1,0},
15+
expectedResult: true,
16+
},
17+
{
18+
name: "Test Case 2",
19+
derived: []int{1,1},
20+
expectedResult: true,
21+
},
22+
{
23+
name: "Test Case 3",
24+
derived: []int{1,0},
25+
expectedResult: false,
26+
},
27+
}
28+
29+
for _, test := range tests {
30+
t.Run(test.name, func(t *testing.T) {
31+
got := doesValidArrayExist(test.derived)
32+
if got != test.expectedResult {
33+
t.Errorf("doesValidArrayExist(%v) = %t; want = %t", test.derived, got, test.expectedResult)
34+
}
35+
})
36+
}
37+
}

0 commit comments

Comments
 (0)