< Summary

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

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\DivideStringIntoGroupsOfSizeK\DivideStringIntoGroupsOfSizeKSimulation.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
 12using System.Text;
 13
 14namespace LeetCode.Algorithms.DivideStringIntoGroupsOfSizeK;
 15
 16/// <inheritdoc />
 17public class DivideStringIntoGroupsOfSizeKSimulation : IDivideStringIntoGroupsOfSizeK
 18{
 19    /// <summary>
 20    ///     Time complexity - O(n)
 21    ///     Space complexity - O(n)
 22    /// </summary>
 23    /// <param name="s"></param>
 24    /// <param name="k"></param>
 25    /// <param name="fill"></param>
 26    /// <returns></returns>
 27    public string[] DivideString(string s, int k, char fill)
 228    {
 229        var groupsCount = (int)Math.Ceiling(s.Length / (double)k);
 30
 231        var result = new string[groupsCount];
 32
 233        var sIndex = 0;
 34
 1835        for (var i = 0; i < groupsCount; i++)
 736        {
 737            var stringBuilder = new StringBuilder();
 38
 5639            for (var j = 0; j < k; j++)
 2140            {
 2141                if (sIndex < s.Length)
 1942                {
 1943                    stringBuilder.Append(s[sIndex]);
 44
 1945                    sIndex++;
 1946                }
 47                else
 248                {
 249                    stringBuilder.Append(fill);
 250                }
 2151            }
 52
 753            result[i] = stringBuilder.ToString();
 754        }
 55
 256        return result;
 257    }
 58}