< Summary

Information
Class: LeetCode.Algorithms.FindThePowerOfKSizeSubarrays1.FindThePowerOfKSizeSubarrays1ConsecutiveCount
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\FindThePowerOfKSizeSubarrays1\FindThePowerOfKSizeSubarrays1ConsecutiveCount.cs
Line coverage
91%
Covered lines: 21
Uncovered lines: 2
Coverable lines: 23
Total lines: 56
Line coverage: 91.3%
Branch coverage
87%
Covered branches: 7
Total branches: 8
Branch coverage: 87.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ResultsArray(...)87.5%8891.3%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\FindThePowerOfKSizeSubarrays1\FindThePowerOfKSizeSubarrays1ConsecutiveCount.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.FindThePowerOfKSizeSubarrays1;
 13
 14/// <inheritdoc />
 15public class FindThePowerOfKSizeSubarrays1ConsecutiveCount : IFindThePowerOfKSizeSubarrays1
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n)
 19    ///     Space complexity - O(n)
 20    /// </summary>
 21    /// <param name="nums"></param>
 22    /// <param name="k"></param>
 23    /// <returns></returns>
 24    public int[] ResultsArray(int[] nums, int k)
 325    {
 326        if (k == 1)
 027        {
 028            return nums;
 29        }
 30
 331        var result = new int[nums.Length - k + 1];
 32
 333        Array.Fill(result, -1);
 34
 335        var consecutiveCount = 1;
 36
 3637        for (var i = 0; i < nums.Length - 1; i++)
 1538        {
 1539            if (nums[i] + 1 == nums[i + 1])
 540            {
 541                consecutiveCount++;
 542            }
 43            else
 1044            {
 1045                consecutiveCount = 1;
 1046            }
 47
 1548            if (consecutiveCount >= k)
 449            {
 450                result[i - k + 2] = nums[i + 1];
 451            }
 1552        }
 53
 354        return result;
 355    }
 56}