< Summary

Information
Class: LeetCode.Algorithms.SolvingQuestionsWithBrainpower.SolvingQuestionsWithBrainpowerDynamicProgramming
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\SolvingQuestionsWithBrainpower\SolvingQuestionsWithBrainpowerDynamicProgramming.cs
Line coverage
100%
Covered lines: 22
Uncovered lines: 0
Coverable lines: 22
Total lines: 54
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
MostPoints(...)100%66100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\SolvingQuestionsWithBrainpower\SolvingQuestionsWithBrainpowerDynamicProgramming.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.SolvingQuestionsWithBrainpower;
 13
 14/// <inheritdoc />
 15public class SolvingQuestionsWithBrainpowerDynamicProgramming : ISolvingQuestionsWithBrainpower
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n)
 19    ///     Space complexity - O(n)
 20    /// </summary>
 21    /// <param name="questions"></param>
 22    /// <returns></returns>
 23    public long MostPoints(int[][] questions)
 224    {
 225        var maximumPoints = new long[questions.Length];
 26
 2227        for (var currentQuestionIndex = questions.Length - 1; currentQuestionIndex >= 0; currentQuestionIndex--)
 928        {
 929            var currentQuestionPoints = questions[currentQuestionIndex][0];
 930            var currentQuestionBrainpower = questions[currentQuestionIndex][1];
 931            var nextSolvableQuestionIndex = currentQuestionIndex + currentQuestionBrainpower + 1;
 32
 933            long solvePoints = currentQuestionPoints;
 34
 935            if (nextSolvableQuestionIndex < questions.Length)
 336            {
 337                solvePoints += maximumPoints[nextSolvableQuestionIndex];
 338            }
 39
 940            long skipPoints = 0;
 41
 942            var nextQuestionIndex = currentQuestionIndex + 1;
 43
 944            if (nextQuestionIndex < questions.Length)
 745            {
 746                skipPoints += maximumPoints[nextQuestionIndex];
 747            }
 48
 949            maximumPoints[currentQuestionIndex] = Math.Max(solvePoints, skipPoints);
 950        }
 51
 252        return maximumPoints[0];
 253    }
 54}

Methods/Properties

MostPoints(System.Int32[][])