Get Distinct Goodness Values
A coding competition organized to hire software engineers includes an interesting problem on Bitwise-OR.
The goodness of a sequence is defined as the bitwise-OR of its elements. Given an array arr of length n, find all possible distinct values of goodness that can be obtained by choosing any strictly increasing subsequence of the array. Sort the return array in non-decreasing order.
Note: A subsequence is a sequence that can be derived from the given sequence by deleting zero or more elements without changing the order of the remaining elements.
Complete the function getGoodnessValue in the editor.
getGoodnessValue has the following parameters:
int arr[n]: an array of integers
Returns
int[]: all possible distinct values of goodness
π· Aura Man the slayer π
1Example 1
2Example 2
3Example 3
Constraints
Limits and guarantees your solution can rely on.
- 1 β€ n, m β€ 10^4
- 1 <= arr[i] < 1024