grid of non-negative integers and an integer k.
The value of cell (a, b) is the XOR of every grid[i][j] in the rectangle stretching from the top-left corner to that cell inclusive, that is, with 0 ≤ i ≤ a and 0 ≤ j ≤ b.
The table has exactly m · n such values. Return the k-th largest of them (k = 1 means the maximum; equal values are counted separately).grid=[[3, 4], [6, 1]], k=1 → 7
Cell values: (0,0) → 3, (0,1) → 3⊕4 = 7, (1,0) → 3⊕6 = 5, (1,1) → 3⊕4⊕6⊕1 = 0. The largest is 7.
grid=[[3, 4], [6, 1]], k=3 → 3
In descending order the values are 7, 5, 3, 0, so the third one is 3.
grid=[[9, 9, 2]], k=2 → 2
grid=[[3, 4], [6, 1]], k=1
7
Run checks the first 3 tests in your browser. Submit checks all 89 tests on the server, hidden ones included.