< Summary

Information
Class: LeetCode.Algorithms.ConstructProductMatrix.ConstructProductMatrixPrefixSum
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\ConstructProductMatrix\ConstructProductMatrixPrefixSum.cs
Line coverage
100%
Covered lines: 29
Uncovered lines: 0
Coverable lines: 29
Total lines: 65
Line coverage: 100%
Branch coverage
100%
Covered branches: 10
Total branches: 10
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ConstructProductMatrix(...)100%1010100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\ConstructProductMatrix\ConstructProductMatrixPrefixSum.cs

#LineLine coverage
 1// --------------------------------------------------------------------------------
 2// Copyright (C) 2026 Eugene Eremeev (also known as Yevhenii Yeriemeieiv).
 3// All Rights Reserved.
 4// --------------------------------------------------------------------------------
 5// This software is the confidential and proprietary information of Eugene Eremeev
 6// (also known as Yevhenii Yeriemeieiv) ("Confidential Information"). You shall not
 7// disclose such Confidential Information and shall use it only in accordance with
 8// the terms of the license agreement you entered into with Eugene Eremeev (also
 9// known as Yevhenii Yeriemeieiv).
 10// --------------------------------------------------------------------------------
 11
 12namespace LeetCode.Algorithms.ConstructProductMatrix;
 13
 14/// <inheritdoc />
 15public sealed class ConstructProductMatrixPrefixSum : IConstructProductMatrix
 16{
 17    private const int Modulo = 12_345;
 18
 19    /// <summary>
 20    ///     Time complexity - O(m * n)
 21    ///     Space complexity - O(1)
 22    /// </summary>
 23    /// <param name="grid"></param>
 24    /// <returns></returns>
 25    public int[][] ConstructProductMatrix(int[][] grid)
 226    {
 227        var m = grid.Length;
 228        var n = grid[0].Length;
 29
 230        var result = new int[m][];
 31
 1432        for (var i = 0; i < m; i++)
 533        {
 534            result[i] = new int[n];
 535        }
 36
 237        var prefix = 1;
 38
 1439        for (var i = 0; i < m; i++)
 540        {
 2441            for (var j = 0; j < n; j++)
 742            {
 743                result[i][j] = prefix;
 44
 745                grid[i][j] %= Modulo;
 46
 747                prefix = prefix * grid[i][j] % Modulo;
 748            }
 549        }
 50
 251        var suffix = 1;
 52
 1453        for (var i = m - 1; i >= 0; i--)
 554        {
 2455            for (var j = n - 1; j >= 0; j--)
 756            {
 757                result[i][j] = result[i][j] * suffix % Modulo;
 58
 759                suffix = suffix * grid[i][j] % Modulo;
 760            }
 561        }
 62
 263        return result;
 264    }
 65}