Maximise the OR Sum Problem Statement

You are provided with two arrays of positive integers. The goal is to select two sub-arrays of the same length, one from each of the provided arrays, such that the sum of the bitwise OR of these sub-arrays is maximized. Return the maximum sum possible.

Example:

Input:
First array: arr1 = [1,5,8,4]
Second array: arr2 = [3,7,16,1]
Output:
26
Explanation:

Select the sub-array {5,8} from the first array (arr1), and the sub-array {7,16} from the second array (arr2). The OR sum is calculated as 13 + 23 = 26, which is the maximum possible.

Constraints:

  • 1 <= T <= 10
  • 1 <= N <= 10^5
  • 1 <= arr1[i], arr2[i] <= 10^5
  • Time Limit: 1 sec.
AnswerBot
4mo

Select two sub-arrays of the same length from two arrays to maximize the sum of bitwise OR.

  • Iterate through all possible sub-arrays of the same length from both arrays.

  • Calculate the bitwise OR sum for ...read more

Help your peers!
Select
Add answer anonymously...
Elgin Industries Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits