Construct Product Matrix
Real-world version: Cross Product PanelThe statement here is our own: the same inputs, outputs and technique.
A calibration panel is a grid of n rows by m columns of readings, given as grid.
Build a second grid panel of the same shape, where panel[i][j] is the product of every reading of grid except the one at row i, column j, taken modulo 12345.
Return panel.
Examples
Example 1
- Input
- grid = [[4, 7], [2, 5]]
- Output
- [[70, 40], [140, 56]]
For the cell holding 4 the other readings are 7, 2 and 5, whose product is 70. For the cell holding 7 they are 4, 2 and 5, giving 40. For 2 they are 4, 7 and 5, giving 140, and for 5 they are 4, 7 and 2, giving 56. All four are below 12345, so the remainder leaves them unchanged.
Example 2
- Input
- grid = [[6], [7]]
- Output
- [[7], [6]]
The panel has one column. The cell holding 6 has only the 7 left, and the cell holding 7 has only the 6.
Example 3
- Input
- grid = [[12345, 4]]
- Output
- [[4, 0]]
For the first cell the remaining product is 4. For the second it is 12345, and 12345 leaves a remainder of 0 on division by 12345.
Constraints
- 1 <= grid.length <= 10^5
- 1 <= grid[0].length <= 10^5
- Every row of grid has the same length, and grid holds at least 2 readings in total
- 1 <= grid[i][j] <= 10^9
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def cross_product_grid(grid: list[list[int]]) -> list[list[int]]:public int[][] crossProductGrid(int[][] grid)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 11 test cases: 11 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Equal Sum Grid Partition IReal-world version: Splitting the Yield Plot in TwoMedium
- Matrix Block SumReal-world version: Neighbourhood Totals On A Sensor PanelMedium
- Get Biggest Three Rhombus Sums in a GridReal-world version: Three Best Diamond Outlines on a BoardMedium
- Count Submatrices With Equal Frequency of X and YReal-world version: Corner Blocks With Matching MarksMedium