3858. Minimum Bitwise OR From Grid Medium

@problem@discussion
#Array#Greedy#Bit Manipulation#Matrix



1/**
2 * [3858] Minimum Bitwise OR From Grid
3 *
4 * You are given a 2D integer array grid of size m x n.
5 * You must select exactly one integer from each row of the grid.
6 * Return an integer denoting the minimum possible bitwise OR of the selected integers from each row.
7 *  
8 * <strong class="example">Example 1:
9 * <div class="example-block">
10 * Input: <span class="example-io">grid = [[1,5],[2,4]]</span>
11 * Output: <span class="example-io">3</span>
12 * Explanation:
13 * 
14 * 	Choose 1 from the first row and 2 from the second row.
15 * 	The bitwise OR of 1 | 2 = 3​​​​​​​, which is the minimum possible.
16 * </div>
17 * <strong class="example">Example 2:
18 * <div class="example-block">
19 * Input: <span class="example-io">grid = [[3,5],[6,4]]</span>
20 * Output: <span class="example-io">5</span>
21 * Explanation:
22 * 
23 * 	Choose 5 from the first row and 4 from the second row.
24 * 	The bitwise OR of 5 | 4 = 5​​​​​​​, which is the minimum possible.
25 * </div>
26 * <strong class="example">Example 3:
27 * <div class="example-block">
28 * Input: <span class="example-io">grid = [[7,9,8]]</span>
29 * Output: <span class="example-io">7</span>
30 * Explanation:
31 * 
32 * 	Choosing 7 gives the minimum bitwise OR.
33 * </div>
34 *  
35 * Constraints:
36 * 
37 * 	1 <= m == grid.length <= 10^5
38 * 	1 <= n == grid[i].length <= 10^5
39 * 	m * n <= 10^5
40 * 	1 <= grid[i][j] <= 10^5​​​​​​​
41 * 
42 */
43pub struct Solution {}
44
45// problem: https://leetcode.com/problems/minimum-bitwise-or-from-grid/
46// discuss: https://leetcode.com/problems/minimum-bitwise-or-from-grid/discuss/?currentPage=1&orderBy=most_votes&query=
47
48// submission codes start here
49
50impl Solution {
51    pub fn minimum_or(grid: Vec<Vec<i32>>) -> i32 {
52        0
53    }
54}
55
56// submission codes end
57
58#[cfg(test)]
59mod tests {
60    use super::*;
61
62    #[test]
63    fn test_3858() {
64    }
65}
66

Back
© 2026 bowen.ge All Rights Reserved.