< Summary

Information
Class: LeetCode.Algorithms.DivideArrayInSetsOfKConsecutiveNumbers.DivideArrayInSetsOfKConsecutiveNumbersSortedDictionary
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\DivideArrayInSetsOfKConsecutiveNumbers\DivideArrayInSetsOfKConsecutiveNumbersSortedDictionary.cs
Line coverage
100%
Covered lines: 34
Uncovered lines: 0
Coverable lines: 34
Total lines: 62
Line coverage: 100%
Branch coverage
100%
Covered branches: 14
Total branches: 14
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
IsPossibleDivide(...)100%1414100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\DivideArrayInSetsOfKConsecutiveNumbers\DivideArrayInSetsOfKConsecutiveNumbersSortedDictionary.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.DivideArrayInSetsOfKConsecutiveNumbers;
 13
 14/// <inheritdoc />
 15public class DivideArrayInSetsOfKConsecutiveNumbersSortedDictionary : IDivideArrayInSetsOfKConsecutiveNumbers
 16{
 17    public bool IsPossibleDivide(int[] nums, int k)
 1518    {
 1519        if (nums.Length % k != 0)
 320        {
 321            return false;
 22        }
 23
 1224        var numsDictionary = new SortedDictionary<int, int>();
 25
 16826        foreach (var num in nums)
 6627        {
 6628            if (!numsDictionary.TryAdd(num, 1))
 1029            {
 1030                numsDictionary[num]++;
 1031            }
 6632        }
 33
 3334        while (numsDictionary.Count > 0)
 2335        {
 2336            var firstNum = numsDictionary.First().Key;
 37
 16838            for (var i = 0; i < k; i++)
 6339            {
 6340                var currentNum = firstNum + i;
 41
 6342                if (numsDictionary.TryGetValue(currentNum, out var value))
 6143                {
 6144                    if (value == 1)
 5345                    {
 5346                        numsDictionary.Remove(currentNum);
 5347                    }
 48                    else
 849                    {
 850                        numsDictionary[currentNum] = value - 1;
 851                    }
 6152                }
 53                else
 254                {
 255                    return false;
 56                }
 6157            }
 2158        }
 59
 1060        return true;
 1561    }
 62}