< Summary

Information
Class: LeetCode.Algorithms.FindCommonCharacters.FindCommonCharactersArray
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\FindCommonCharacters\FindCommonCharactersArray.cs
Line coverage
100%
Covered lines: 25
Uncovered lines: 0
Coverable lines: 25
Total lines: 56
Line coverage: 100%
Branch coverage
100%
Covered branches: 10
Total branches: 10
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
CommonChars(...)100%1010100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\FindCommonCharacters\FindCommonCharactersArray.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.FindCommonCharacters;
 13
 14/// <inheritdoc />
 15public class FindCommonCharactersArray : IFindCommonCharacters
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n * m), where n is the number of words and m is the maximum length of the words
 19    ///     Space complexity - O(n * m), where n is the number of words and m is the maximum length of the words
 20    /// </summary>
 21    /// <param name="words"></param>
 22    /// <returns></returns>
 23    public IList<string> CommonChars(string[] words)
 924    {
 925        var minFrequency = new int[26];
 26
 927        Array.Fill(minFrequency, int.MaxValue);
 28
 8329        foreach (var word in words)
 2830        {
 2831            var charCount = new int[26];
 32
 32233            foreach (var c in word)
 11934            {
 11935                charCount[c - 'a']++;
 11936            }
 37
 151238            for (var i = 0; i < 26; i++)
 72839            {
 72840                minFrequency[i] = Math.Min(minFrequency[i], charCount[i]);
 72841            }
 2842        }
 43
 944        var commonChars = new List<string>();
 45
 48646        for (var i = 0; i < 26; i++)
 23447        {
 50048            for (var j = 0; j < minFrequency[i]; j++)
 1649            {
 1650                commonChars.Add(((char)(i + 'a')).ToString());
 1651            }
 23452        }
 53
 954        return commonChars;
 955    }
 56}

Methods/Properties

CommonChars(System.String[])