Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b1d14ff

Browse files
committed
Add solution #2683
1 parent 2150b58 commit b1d14ff

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

2683-neighboring-bitwise-xor.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* 2683. Neighboring Bitwise XOR
3+
* https://leetcode.com/problems/neighboring-bitwise-xor/
4+
* Difficulty: Medium
5+
*
6+
* A 0-indexed array derived with length n is derived by computing the bitwise XOR (⊕)
7+
* of adjacent values in a binary array original of length n.
8+
*
9+
* Specifically, for each index i in the range [0, n - 1]:
10+
* - If i = n - 1, then derived[i] = original[i] ⊕ original[0].
11+
* - Otherwise, derived[i] = original[i] ⊕ original[i + 1].
12+
*
13+
* Given an array derived, your task is to determine whether there exists a valid binary
14+
* array original that could have formed derived.
15+
*
16+
* Return true if such an array exists or false otherwise.
17+
* - A binary array is an array containing only 0's and 1's
18+
*/
19+
20+
/**
21+
* @param {number[]} derived
22+
* @return {boolean}
23+
*/
24+
var doesValidArrayExist = function(derived) {
25+
return derived.reduce((xor, n) => xor ^ n, 0) === 0;
26+
};

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@
447447
2666|[Allow One Function Call](./2666-allow-one-function-call.js)|Easy|
448448
2667|[Create Hello World Function](./2667-create-hello-world-function.js)|Easy|
449449
2677|[Chunk Array](./2677-chunk-array.js)|Easy|
450+
2683|[Neighboring Bitwise XOR](./2683-neighboring-bitwise-xor.js)|Medium|
450451
2693|[Call Function with Custom Context](./2693-call-function-with-custom-context.js)|Medium|
451452
2695|[Array Wrapper](./2695-array-wrapper.js)|Easy|
452453
2703|[Return Length of Arguments Passed](./2703-return-length-of-arguments-passed.js)|Easy|

0 commit comments

Comments
 (0)