< Summary

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

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\CountLargestGroup\CountLargestGroupFrequencyDictionary.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.CountLargestGroup;
 13
 14/// <inheritdoc />
 15public class CountLargestGroupFrequencyDictionary : ICountLargestGroup
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n log n)
 19    ///     Space complexity - O(log n)
 20    /// </summary>
 21    /// <param name="n"></param>
 22    /// <returns></returns>
 23    public int CountLargestGroup(int n)
 224    {
 225        var count = 0;
 226        var max = 0;
 27
 228        var frequencyDictionary = new Dictionary<int, int>();
 29
 3430        for (var i = 1; i <= n; i++)
 1531        {
 1532            var sum = 0;
 33
 1534            var num = i;
 35
 3436            while (num > 0)
 1937            {
 1938                sum += num % 10;
 1939                num /= 10;
 1940            }
 41
 1542            if (!frequencyDictionary.TryAdd(sum, 1))
 443            {
 444                frequencyDictionary[sum]++;
 445            }
 46
 1547            if (frequencyDictionary[sum] > max)
 348            {
 349                max = frequencyDictionary[sum];
 50
 351                count = 1;
 352            }
 1253            else if (frequencyDictionary[sum] == max)
 1254            {
 1255                count++;
 1256            }
 1557        }
 58
 259        return count;
 260    }
 61}

Methods/Properties

CountLargestGroup(System.Int32)