< Summary

Information
Class: LeetCode.Algorithms.LexicographicallyMinimumStringAfterRemovingStars.LexicographicallyMinimumStringAfterRemovingStarsTwoArrays
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\LexicographicallyMinimumStringAfterRemovingStars\LexicographicallyMinimumStringAfterRemovingStarsTwoArrays.cs
Line coverage
90%
Covered lines: 29
Uncovered lines: 3
Coverable lines: 32
Total lines: 74
Line coverage: 90.6%
Branch coverage
80%
Covered branches: 8
Total branches: 10
Branch coverage: 80%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ClearStars(...)80%101090.62%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\LexicographicallyMinimumStringAfterRemovingStars\LexicographicallyMinimumStringAfterRemovingStarsTwoArrays.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.LexicographicallyMinimumStringAfterRemovingStars;
 13
 14/// <inheritdoc />
 15public class LexicographicallyMinimumStringAfterRemovingStarsTwoArrays :
 16    LexicographicallyMinimumStringAfterRemovingStarsBase
 17{
 18    private const int Length = 'z' - 'a' + 1;
 19
 20    /// <summary>
 21    ///     Time complexity - O(n)
 22    ///     Space complexity - O(n)
 23    /// </summary>
 24    /// <param name="s"></param>
 25    /// <returns></returns>
 26    public override string ClearStars(string s)
 227    {
 228        var chars = s.ToCharArray();
 29
 230        var n = chars.Length;
 31
 232        var latestIndexes = new int[Length];
 33
 10834        for (var i = 0; i < latestIndexes.Length; i++)
 5235        {
 5236            latestIndexes[i] = -1;
 5237        }
 38
 239        var previousIndexes = new int[n];
 40
 241        var smallestIndex = Length;
 42
 2043        for (var index = 0; index < n; index++)
 844        {
 845            var c = chars[index];
 46
 847            if (c == '*')
 148            {
 149                var latestIndex = latestIndexes[smallestIndex];
 50
 151                latestIndexes[smallestIndex] = previousIndexes[latestIndex];
 52
 153                chars[latestIndex] = '*';
 54
 155                while (smallestIndex < Length && latestIndexes[smallestIndex] == -1)
 056                {
 057                    smallestIndex++;
 058                }
 159            }
 60            else
 761            {
 762                var letterIndex = c - 'a';
 63
 764                previousIndexes[index] = latestIndexes[letterIndex];
 65
 766                latestIndexes[letterIndex] = index;
 67
 768                smallestIndex = Math.Min(smallestIndex, letterIndex);
 769            }
 870        }
 71
 272        return BuildResult(chars);
 273    }
 74}

Methods/Properties

ClearStars(System.String)