Given a number N and an array of N elements, find the Bitwise XOR of the array elements.
Input Size : N <= 100000
Sample Testcase :
INPUT
2
2 4
OUTPUT
6
// ONE TESTCASE PASSED
const readline = require("readline");
const inp = readline.createInterface({
input: process.stdin
});
const userInput = [];
inp.on("line", (data) => {
userInput.push(data);
});
inp.on("close", () => {
var N = Number(userInput[0]);
var str =String(userInput[1])
var arr = str.split(' ').map((val)=>Number(val))
var first = arr[0]
for(i=1;i<N;i++)
{ first =first^arr[i]}
console.log(first)
});
Given a number N and an array of N elements, find the Bitwise OR of the array elements.
Input Size : N <= 100000
Sample Testcase :
INPUT
2
2 4
OUTPUT
6
const readline = require("readline");
const inp = readline.createInterface({
input: process.stdin
});
const userInput = [];
inp.on("line", (data) => {
userInput.push(data);
});
inp.on("close", () => {
var N = Number(userInput[0]);
var str =String(userInput[1])
var arr = str.split(' ').map((val)=>Number(val))
var first = arr[0]
for(i=1;i<N;i++)
{ first =first|arr[i]}
console.log(first)
});
Comments
Post a Comment