< Summary

Information
Class: LeetCode.Algorithms.PathWithMaximumProbability.PathWithMaximumProbabilityBase
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\PathWithMaximumProbability\PathWithMaximumProbabilityBase.cs
Line coverage
100%
Covered lines: 21
Uncovered lines: 0
Coverable lines: 21
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
GetEdgesDictionary(...)100%66100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\PathWithMaximumProbability\PathWithMaximumProbabilityBase.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.PathWithMaximumProbability;
 13
 14public abstract class PathWithMaximumProbabilityBase : IPathWithMaximumProbability
 15{
 16    public abstract double MaxProbability(int n, int[][] edges, double[] successProbability, int startNode,
 17        int endNode);
 18
 19    /// <summary>
 20    ///     Time Complexity - O(n), where n is the number of edges
 21    ///     Time Complexity - O(n + m), where n is the number of edges and m is the number of edges
 22    /// </summary>
 23    /// <param name="edges"></param>
 24    /// <param name="successProbability"></param>
 25    /// <returns></returns>
 26    protected static Dictionary<int, List<(int Node, double Probability)>> GetEdgesDictionary(int[][] edges,
 27        double[] successProbability)
 1428    {
 1429        var edgesDictionary = new Dictionary<int, List<(int Node, double Probability)>>();
 30
 19631        for (var i = 0; i < edges.Length; i++)
 8432        {
 8433            if (edgesDictionary.TryGetValue(edges[i][0], out var headEdge))
 6634            {
 6635                headEdge.Add((edges[i][1], successProbability[i]));
 6636            }
 37            else
 1838            {
 1839                edgesDictionary[edges[i][0]] = [(edges[i][1], successProbability[i])];
 1840            }
 41
 8442            if (edgesDictionary.TryGetValue(edges[i][1], out var tailEdge))
 1843            {
 1844                tailEdge.Add((edges[i][0], successProbability[i]));
 1845            }
 46            else
 6647            {
 6648                edgesDictionary[edges[i][1]] = [(edges[i][0], successProbability[i])];
 6649            }
 8450        }
 51
 1452        return edgesDictionary;
 1453    }
 54}