< Summary

Information
Class: LeetCode.Algorithms.CountResiduePrefixes.CountResiduePrefixesLookup
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\CountResiduePrefixes\CountResiduePrefixesLookup.cs
Line coverage
100%
Covered lines: 19
Uncovered lines: 0
Coverable lines: 19
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
ResiduePrefixes(...)100%66100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\CountResiduePrefixes\CountResiduePrefixesLookup.cs

#LineLine coverage
 1// --------------------------------------------------------------------------------
 2// Copyright (C) 2026 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.CountResiduePrefixes;
 13
 14/// <inheritdoc />
 15public sealed class CountResiduePrefixesLookup : ICountResiduePrefixes
 16{
 17    private const byte AlphabetLength = 'z' - 'a' + 1;
 18
 19    /// <summary>
 20    ///     Time complexity - O(n)
 21    ///     Space complexity - O(1)
 22    /// </summary>
 23    /// <param name="s"></param>
 24    /// <returns></returns>
 25    public int ResiduePrefixes(string s)
 326    {
 327        var result = 0;
 28
 329        Span<bool> lookup = stackalloc bool[AlphabetLength];
 30
 331        var distinctCount = 0;
 32
 2233        for (var i = 0; i < s.Length; i++)
 834        {
 835            var index = s[i] - 'a';
 36
 837            if (!lookup[index])
 638            {
 639                distinctCount++;
 40
 641                lookup[index] = true;
 642            }
 43
 844            if (distinctCount == (i + 1) % 3)
 545            {
 546                result++;
 547            }
 848        }
 49
 350        return result;
 351    }
 52}

Methods/Properties

ResiduePrefixes(System.String)