< Summary

Information
Class: LeetCode.Algorithms.FindTheKthCharacterInStringGame1.FindTheKthCharacterInStringGame1StringBuilder
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\FindTheKthCharacterInStringGame1\FindTheKthCharacterInStringGame1StringBuilder.cs
Line coverage
100%
Covered lines: 16
Uncovered lines: 0
Coverable lines: 16
Total lines: 48
Line coverage: 100%
Branch coverage
83%
Covered branches: 5
Total branches: 6
Branch coverage: 83.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
KthCharacter(...)100%44100%
NextChar(...)50%22100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\FindTheKthCharacterInStringGame1\FindTheKthCharacterInStringGame1StringBuilder.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.FindTheKthCharacterInStringGame1;
 15
 16/// <inheritdoc />
 17public class FindTheKthCharacterInStringGame1StringBuilder : IFindTheKthCharacterInStringGame1
 18{
 19    /// <summary>
 20    ///     Time complexity - O(k)
 21    ///     Space complexity - O(k)
 22    /// </summary>
 23    /// <param name="k"></param>
 24    /// <returns></returns>
 25    public char KthCharacter(int k)
 226    {
 227        var stringBuilder = new StringBuilder("a");
 28
 929        while (stringBuilder.Length < k)
 730        {
 731            var length = stringBuilder.Length;
 32
 5833            for (var i = 0; i < length; i++)
 2234            {
 2235                var nextChar = NextChar(stringBuilder[i]);
 36
 2237                stringBuilder.Append(nextChar);
 2238            }
 739        }
 40
 241        return stringBuilder[k - 1];
 242    }
 43
 44    private static char NextChar(char c)
 2245    {
 2246        return c == 'z' ? 'a' : (char)(c + 1);
 2247    }
 48}