ans
to store all unique bitwise OR results.cur
to store unique bitwise OR results of subarrays ending at the current element.A[k]
in the array:
a. Initialize an empty set nextCur
.
b. Add A[k]
to nextCur
.
c. For each element x
in cur
, add x | A[k]
to nextCur
.
d. Set cur
to nextCur
.
e. Add all elements of cur
to ans
.ans
as the number of distinct bitwise ORs.