1
/** https://leetcode.com/problems/bitwise-ors-of-subarrays/2
* @param {number[]} arr5
var subarrayBitwiseORs = function (arr) {6
// Hashset to store the unique bitwise7
this.uniqueBw = new Set();10
dp(arr, arr.length - 1);12
return this.uniqueBw.size;15
var dp = function (arr, currIdx) {16
// Base, reach beginning of the array18
// Store the value to unique bitwise, since it's only single number, we store the actual value19
this.uniqueBw.add(arr[0]);25
// DP to previous index26
let prev = dp(arr, currIdx - 1);28
// Number at current index29
let firstBw = arr[currIdx];31
// Add number at current index to hashset, since it's only single number, we store the actual value32
this.uniqueBw.add(firstBw);34
// Another hashset to store the result of bitwise operation between number at current index with result from previous index35
let currRes = new Set();38
// Loop through result form previous index39
for (let i = 0; i < prev.length; i++) {40
// Perform bitwise operation OR41
let curr = arr[currIdx] | prev[i];43
// Add to unique bitwise collection44
this.uniqueBw.add(curr);46
// Add to current result50
// Return current result as an array