< Summary

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

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
MinSteps(...)100%88100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\TwoKeysKeyboard\TwoKeysKeyboardSimulation.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.TwoKeysKeyboard;
 13
 14/// <inheritdoc />
 15public class TwoKeysKeyboardSimulation : ITwoKeysKeyboard
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n)
 19    ///     Space complexity - O(1)
 20    /// </summary>
 21    /// <param name="n"></param>
 22    /// <returns></returns>
 23    public int MinSteps(int n)
 1624    {
 1625        var minSteps = 0;
 1626        var currentN = 1;
 1627        var copiedCount = 0;
 28
 1629        var paste = false;
 30
 334031        while (currentN < n)
 332432        {
 332433            if (paste)
 166234            {
 166235                currentN += copiedCount;
 166236                minSteps++;
 37
 166238                paste = false;
 166239            }
 40            else
 166241            {
 166242                if (copiedCount > 0)
 164743                {
 164744                    if (n % currentN == 0)
 1945                    {
 1946                        copiedCount = currentN;
 1947                        minSteps++;
 1948                    }
 164749                }
 50                else
 1551                {
 1552                    copiedCount = 1;
 1553                    minSteps++;
 1554                }
 55
 166256                paste = true;
 166257            }
 332458        }
 59
 1660        return minSteps;
 1661    }
 62}

Methods/Properties

MinSteps(System.Int32)