< Summary

Information
Class: LeetCode.Algorithms.GridGame.GridGamePrefixSum
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\GridGame\GridGamePrefixSum.cs
Line coverage
100%
Covered lines: 25
Uncovered lines: 0
Coverable lines: 25
Total lines: 59
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
GridGame(...)100%66100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\GridGame\GridGamePrefixSum.cs

#LineLine coverage
 1// --------------------------------------------------------------------------------
 2// Copyright (C) 2025 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.GridGame;
 13
 14/// <inheritdoc />
 15public class GridGamePrefixSum : IGridGame
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n)
 19    ///     Space complexity - O(n)
 20    /// </summary>
 21    /// <param name="grid"></param>
 22    /// <returns></returns>
 23    public long GridGame(int[][] grid)
 324    {
 325        var n = grid[0].Length;
 26
 327        var topPrefixSum = new long[n];
 328        var bottomPrefixSum = new long[n];
 29
 330        topPrefixSum[0] = grid[0][0];
 331        bottomPrefixSum[0] = grid[1][0];
 32
 2033        for (var i = 1; i < n; i++)
 734        {
 735            topPrefixSum[i] = topPrefixSum[i - 1] + grid[0][i];
 736            bottomPrefixSum[i] = bottomPrefixSum[i - 1] + grid[1][i];
 737        }
 38
 339        var result = long.MaxValue;
 40
 2641        for (var i = 0; i < n; i++)
 1042        {
 1043            var topRemaining = topPrefixSum[n - 1] - topPrefixSum[i];
 44
 1045            long bottomCollected = 0;
 46
 1047            if (i > 0)
 748            {
 749                bottomCollected = bottomPrefixSum[i - 1];
 750            }
 51
 1052            var secondRobotPoints = Math.Max(topRemaining, bottomCollected);
 53
 1054            result = Math.Min(result, secondRobotPoints);
 1055        }
 56
 357        return result;
 358    }
 59}

Methods/Properties

GridGame(System.Int32[][])