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 🙌
arr = [4, 2, 4, 1] return = [0, 1, 2, 4, 6]
arr = [3, 2, 4, 6] return = [0, 2, 3, 4, 6, 7]
arr = [3, 5, 5, 1] return = [0, 1, 3, 5, 7]
- 1 ≤ n, m ≤ 10^4
- 1 <= arr[i] < 1024
- Minimum Path Sum to Target in Binary TreePHONE SCREEN · Seen Apr 2026
- Social Media SuggestionsSeen May 2025
- Best Sum Downward Tree PathSeen May 2025
- Price CheckSeen Feb 2025
- Palindromic Substrings (LC 647 :)Seen Jan 2025
- Get Min OperationsSeen Jan 2025
- Count Stable SegmentsSeen Jan 2025
- Find Consistent LogsSeen Oct 2024
public int[] getGoodnessValue(int[] arr) {
// write your code here
}