< Summary

Information
Class: LeetCode.Algorithms.MaximumNumberOfPointsWithCost.MaximumNumberOfPointsWithCostDynamicProgramming
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\MaximumNumberOfPointsWithCost\MaximumNumberOfPointsWithCostDynamicProgramming.cs
Line coverage
100%
Covered lines: 27
Uncovered lines: 0
Coverable lines: 27
Total lines: 59
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
MaxPoints(...)100%1010100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\MaximumNumberOfPointsWithCost\MaximumNumberOfPointsWithCostDynamicProgramming.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.MaximumNumberOfPointsWithCost;
 13
 14/// <inheritdoc />
 15public class MaximumNumberOfPointsWithCostDynamicProgramming : IMaximumNumberOfPointsWithCost
 16{
 17    /// <summary>
 18    ///     Time complexity - O(m * n)
 19    ///     Space complexity - O(n)
 20    /// </summary>
 21    /// <param name="points"></param>
 22    /// <returns></returns>
 23    public long MaxPoints(int[][] points)
 724    {
 725        var scores = new long[points[0].Length];
 26
 6827        for (var j = 0; j < points[0].Length; j++)
 2728        {
 2729            scores[j] = points[0][j];
 2730        }
 31
 4232        for (var i = 1; i < points.Length; i++)
 1433        {
 1434            var leftMax = new long[points[i].Length];
 1435            var rightMax = new long[points[i].Length];
 36
 1437            leftMax[0] = scores[0];
 38
 13639            for (var j = 1; j < points[i].Length; j++)
 5440            {
 5441                leftMax[j] = Math.Max(leftMax[j - 1], scores[j] + j);
 5442            }
 43
 1444            rightMax[points[i].Length - 1] = scores[points[i].Length - 1] - (points[i].Length - 1);
 45
 13646            for (var j = points[i].Length - 2; j >= 0; j--)
 5447            {
 5448                rightMax[j] = Math.Max(rightMax[j + 1], scores[j] - j);
 5449            }
 50
 16451            for (var j = 0; j < points[i].Length; j++)
 6852            {
 6853                scores[j] = points[i][j] + Math.Max(leftMax[j] - j, rightMax[j] + j);
 6854            }
 1455        }
 56
 757        return scores.Max();
 758    }
 59}

Methods/Properties

MaxPoints(System.Int32[][])