Distinct OR Values of Increasing Subsequences
Updated
Problem statement
The goodness of a sequence is the bitwise OR of all its elements. The empty sequence has goodness 0.
Given arr, consider every strictly increasing subsequence: chosen indices must preserve their original order, and each chosen value must be strictly larger than the previous chosen value.
Return every distinct goodness value in ascending order, including 0.
Function
distinctOrIncreasingSubsequences(arr: int[]) → int[]Examples
Example 1
arr = [4,2,4,1]return = [0,1,2,4,6]Distinct values come from the empty subsequence, singletons, and [2,4] with OR 6.
Example 2
arr = [3,2,4,6]return = [0,2,3,4,6,7]For example, [3,4] contributes 7; duplicate scores are returned once.
Example 3
arr = [5,5,5]return = [0,5]Equal values cannot follow one another in a strictly increasing subsequence.
Constraints
1 <= arr.length <= 10000.1 <= arr[i] < 1024.
More Scale AI Online Assessment questions
- Part 2: Batch Access ReviewOA · Seen Nov 2026
- Part 1: The Narrowest KeyOA · Seen Nov 2026
- Build Sessions from Unordered Events (Part 1)OA · Seen Oct 2026
- Match Billing Charges to User Sessions (Part 2)OA · Seen Oct 2026
- Four-Player Trick-Taking Card Game SimulationOA · PHONE SCREEN · Seen Aug 2026
- Free Windows Between Busy IntervalsOA · PHONE SCREEN · Seen Apr 2026
- Compare Labeling Worker AnnotationsOA · Seen Mar 2025
- Count Stable Server SubsegmentsOA · Seen Nov 2024
- Running Through Walls with Limited EnergyOA · Seen Sep 2024
- Relative Score Graph ComponentsOA · Seen Sep 2023
Similar questions at other companies
- Delete K Subsets for Maximum ScoreRubrik · OA
- Optimize Discount Selection Under a Point BudgetPalantir · OA
- Maximum Index-Weighted Sum with Disjoint SwapsVisa · OA
- Vehicle Builds for Required Terrain (Game Adaptation)Roblox · OA
- Bitwise XOR SubsequencesJP Morgan Chase · OA
- Bitwise XOR SubsequencesGoldman Sachs · OA
- Optimal Account BalancingAmazon · ONSITE INTERVIEW
- Minimum Racks for Server ResourcesGoogle · PHONE SCREEN
- Minimum Cost for a Target WeightPace Stock Broking Services · PHONE SCREEN
- Smallest Sufficient TeamExpedia · ONSITE INTERVIEW