Minimum Bitwise OR From Grid

You are given a 2D integer array grid of size m x n.

You must select exactly one integer from each row of the grid.

Return an integer denoting the minimum possible bitwise OR of the selected integers from each row.

Example 1
1 5
2 4
Inputgrid = [[1,5],[2,4]]
Output3
Choose 1 from the first row and 2 from the second row, and the bitwise OR of 1 | 2 = 3 is the minimum possible.
Example 2
3 5
6 4
Inputgrid = [[3,5],[6,4]]
Output5
Choose 5 from the first row and 4 from the second row, and the bitwise OR of 5 | 4 = 5 is the minimum possible.

Constraints

  • 1 <= m == grid.length <= 10^5
  • 1 <= n == grid[i].length <= 10^5
  • m * n <= 10^5
  • 1 <= grid[i][j] <= 10^5

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate