FastPrepDistinct Bitwise-OR Scores of Increasing Subsequences
Problem · Dynamic Programming

Distinct Bitwise-OR Scores of Increasing Subsequences

Learn this problem
HardWalmart logoWalmartNEW GRADOA

Problem statement

A coding competition organized to recruit software developers includes a problem involving the bitwise-OR operation.

The score of a sequence is defined as the result of the bitwise-OR operation on its elements. Given an array arr of length n, identify all possible distinct scores that can be obtained by selecting any strictly increasing subsequence from the array. Return the results sorted in ascending order.

Note: A subsequence is a sequence that can be derived from the given sequence by deleting zero or more elements without altering the order of the remaining elements.

Function

getDistinctScorsValues(arr: int[]) → int[]

Complete the function getDistinctScorsValues in the editor with the following parameter:

  • int arr[n]: an array of integers

Returns: int[]: all possible distinct score values, sorted ascending.

Examples

Example 1

arr = [4,2,4,1]return = [0,1,2,4,6]

Example: n = 4.

arr = (4, 2, 4, 1)

There are n = 4 elements in the array. The strictly increasing subsequences that can be chosen to have distinct score values are:

  • Empty subsequence; score = 0
  • [1]; score = 1
  • [2]; score = 2
  • [4]; score = 4
  • [2, 4]; score = 6

There are no other strictly increasing subsequences that yield a different score value. So, the answer is (0, 1, 2, 4, 6), which is sorted in ascending order.

Constraints

  • 1 ≤ n ≤ 10^4
  • 1 ≤ arr[i] < 1024

More Walmart problems

drafts saved locally
public int[] getDistinctScorsValues(int[] arr) {
    // Write your code here.
}
arr[4,2,4,1]
expected[0,1,2,4,6]
checking account