#3393

Count Paths With the Given XOR Value

expert · 1010 · lc medium +32 · 40.6% accepted · 91 likes · top 20%

Description

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

Count the number of paths from the top-left cell (0, 0) to the bottom-right cell (m - 1, n - 1) subject to:

- At each step you may move right or down. From cell (i, j) you may go to (i, j + 1) or (i + 1, j) if the target cell exists.

- The XOR of all values on the path equals k.

Return the total number of such paths.

Since the answer may be very large, return it modulo 109 + 7.

Code

1
2
3