Minimum XOR Path in a Grid
You are given a 2D integer array grid of size m * n.
You start at the top-left cell (0, 0) and want to reach the bottom-right cell (m - 1, n - 1).
At each step, you may move either right or down.
The cost of a path is defined as the bitwise XOR of all the values in the cells along that path, including the start and end cells.
Return the minimum possible XOR value among all valid paths from (0, 0) to (m - 1, n - 1).
Example 1
1 2 3 4
Input
grid = [[1,2],[3,4]]Output
6The two valid paths have XOR values 7 and 6, so the minimum XOR value is 6.
Example 2
6 7 5 8
Input
grid = [[6,7],[5,8]]Output
9The two valid paths have XOR values 9 and 11, so the minimum XOR value is 9.
Constraints
- 1 <= m == grid.length <= 1000
- 1 <= n == grid[i].length <= 1000
- m * n <= 1000
- 0 <= grid[i][j] <= 1023