2daysbeforeinterview
Home1Companies2Problems3Experiences4Compensation5Assistant

Spaces

Saved work

Your prep

Notes6Bookmarks7Submissions

Community

Leaderboard8Send feedback
Contribute9
2daysbeforeinterview
2daysbeforeinterview

Straight from the interview room.

Browse

  • Companies
  • Problems
  • Experiences
  • Compensation
  • Leaderboard
  • Pricing

Contribute

  • Add a question
  • Share an experience
  • Report compensation
  • Committed Contributor
  • Send feedback

About

  • About 2daysbeforeinterview
  • Contact
  • Privacy
  • Terms
  • Refunds
  • Delivery

© 2026 2daysbeforeinterview

  • Instagram(opens in a new tab)
  • YouTube(opens in a new tab)
  • X (Twitter)(opens in a new tab)
  • help@2daysbeforeinterview.com
HomeCompaniesProblems
Keep holding ⌥Alt and press a number · ? for every shortcut
Back
DSA
1 reportlast asked …
Arcana

Distinct OR scores of increasing subsequences

The score of a subsequence is the bitwise OR of all its elements (the empty subsequence has score 0). Given an integer array arr, find every distinct score achievable by a strictly increasing subsequence of arr, and return the values sorted in ascending order.

A subsequence keeps the index order of arr, and its values must be strictly increasing.

Example 1

Input:  arr = [3,2,4,6]
Output: [0,2,3,4,6,7]

Singletons give 2, 3, 4 and 6; [2,4] gives 2 | 4 = 6 and [3,4] gives 3 | 4 = 7. Longer chains such as [2,4,6] (OR 6) and [3,4,6] (OR 7) add no new values, and 0 comes from the empty subsequence.

Example 2

Input:  arr = [4,2,4,1]
Output: [0,1,2,4,6]

The second 4 can extend the earlier 2 (indices in order, values increasing), giving 6, but the trailing 1 extends nothing.

Example 3

Input:  arr = [1,2,4]
Output: [0,1,2,3,4,5,6,7]

Here a longer chain does matter: 7 is reachable only through the full subsequence [1,2,4].

Constraints

  • 1 <= arr.length <= 10^4
  • 1 <= arr[i] <= 1024, so every score is below 2048

Hints

0/3

Domains

Backend
asked Jul 2026Report
Discussion
Related questions
Asked atArcana
My notes
Practice
EditorialLocked
Community solutions
Learning resources(3)
Arcana
Arcana