< Summary

Information
Class: LeetCode.Algorithms.WordSubsets.WordSubsetsFrequencyFiltering
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\WordSubsets\WordSubsetsFrequencyFiltering.cs
Line coverage
100%
Covered lines: 26
Uncovered lines: 0
Coverable lines: 26
Total lines: 63
Line coverage: 100%
Branch coverage
100%
Covered branches: 12
Total branches: 12
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
WordSubsets(...)100%1212100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\WordSubsets\WordSubsetsFrequencyFiltering.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.WordSubsets;
 13
 14/// <inheritdoc />
 15public class WordSubsetsFrequencyFiltering : IWordSubsets
 16{
 17    private const int LettersCount = 'z' - 'a' + 1;
 18
 19    /// <summary>
 20    ///     Time complexity - O(words1.Length + words2.Length)
 21    ///     Space complexity - O(words1.Length)
 22    /// </summary>
 23    /// <param name="words1"></param>
 24    /// <param name="words2"></param>
 25    /// <returns></returns>
 26    public IList<string> WordSubsets(string[] words1, string[] words2)
 227    {
 228        var maxCharFrequencies = new int[LettersCount];
 29
 1430        foreach (var word in words2)
 431        {
 432            var tempFrequency = new int[maxCharFrequencies.Length];
 33
 2034            foreach (var c in word)
 435            {
 436                tempFrequency[c - 'a']++;
 37
 438                maxCharFrequencies[c - 'a'] = Math.Max(maxCharFrequencies[c - 'a'], tempFrequency[c - 'a']);
 439            }
 440        }
 41
 242        var result = new List<string>();
 43
 2644        foreach (var word in words1)
 1045        {
 1046            var wordFrequency = new int[maxCharFrequencies.Length];
 47
 16248            foreach (var c in word)
 6649            {
 6650                wordFrequency[c - 'a']++;
 6651            }
 52
 20353            if (wordFrequency.Where((t, i) => t < maxCharFrequencies[i]).Any())
 454            {
 455                continue;
 56            }
 57
 658            result.Add(word);
 659        }
 60
 261        return result;
 262    }
 63}