Optimal Division
Practice
5 (2 votes)
Binary search
Algorithms
Problem
72% Success 629 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You have an array \(A\) of length \(N\). You have to divide the array into atmost \(M\) consecutive segments such that the maximum bitwise OR of these segments is minimum.

Find the minimum possible maximum Bitwise OR of these segments if you divide optimally.

Input Format:

  • The first line contains an integer \(T\), denoting the number of test cases.
  • The first line contains two integers, \(N\) and \(M\).
  • The next line contains \(N\) space-separated integers, elements of array \(A\).

Output Format:

For each test case, print the minimum possible maximum Bitwise OR of these segments if you divide optimally.

Constraints:

\(1\leq T \leq 10 \\ 1 \leq M \leq N \leq 10^5 \\ 1 \leq A[i] \leq 10^9\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
5 votes
Tags:
AlgorithmsBinary SearchMediumSearching
Points:30
5 votes
Tags:
AlgorithmsApprovedBinary SearchMediumOpenSorting
Points:30
16 votes
Tags:
Binary SearchAlgorithms