< Summary

Information
Class: LeetCode.Algorithms.FindKthBitInNthBinaryString.FindKthBitInNthBinaryStringBruteForce
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\FindKthBitInNthBinaryString\FindKthBitInNthBinaryStringBruteForce.cs
Line coverage
100%
Covered lines: 18
Uncovered lines: 0
Coverable lines: 18
Total lines: 52
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
FindKthBit(...)100%22100%
ModifyString(...)100%44100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\FindKthBitInNthBinaryString\FindKthBitInNthBinaryStringBruteForce.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.FindKthBitInNthBinaryString;
 15
 16/// <inheritdoc />
 17public class FindKthBitInNthBinaryStringBruteForce : IFindKthBitInNthBinaryString
 18{
 19    /// <summary>
 20    ///     Time complexity - O(2^n)
 21    ///     Space complexity - O(2^n)
 22    /// </summary>
 23    /// <param name="n"></param>
 24    /// <param name="k"></param>
 25    /// <returns></returns>
 26    public char FindKthBit(int n, int k)
 227    {
 228        var s = "0";
 29
 1430        for (var i = 0; i < n - 1; i++)
 531        {
 532            s = ModifyString(s);
 533        }
 34
 235        return s[k - 1];
 236    }
 37
 38    private static string ModifyString(string s)
 539    {
 540        var stringBuilder = new StringBuilder();
 41
 542        stringBuilder.Append(s);
 543        stringBuilder.Append('1');
 44
 4045        for (var i = s.Length - 1; i >= 0; i--)
 1546        {
 1547            stringBuilder.Append(s[i] == '0' ? '1' : '0');
 1548        }
 49
 550        return stringBuilder.ToString();
 551    }
 52}