< Summary

Information
Class: LeetCode.Algorithms.FindWordsContainingCharacter.FindWordsContainingCharacterDictionary
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\FindWordsContainingCharacter\FindWordsContainingCharacterDictionary.cs
Line coverage
100%
Covered lines: 17
Uncovered lines: 0
Coverable lines: 17
Total lines: 48
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
FindWordsContaining(...)100%88100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\FindWordsContainingCharacter\FindWordsContainingCharacterDictionary.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.FindWordsContainingCharacter;
 13
 14/// <inheritdoc />
 15public class FindWordsContainingCharacterDictionary : IFindWordsContainingCharacter
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n * k), where n is the number of words in the words array, and k is the average number o
 19    ///     unique characters per word
 20    ///     Space complexity - O(n * k), where n is the number of words in the words array, and k is the average number 
 21    ///     unique characters per word
 22    /// </summary>
 23    /// <param name="words"></param>
 24    /// <param name="x"></param>
 25    /// <returns></returns>
 26    public IList<int> FindWordsContaining(string[] words, char x)
 327    {
 328        var charToWordIndexDictionary = new Dictionary<char, List<int>>();
 29
 2630        for (var i = 0; i < words.Length; i++)
 1031        {
 1032            var uniqueChars = new HashSet<char>(words[i]);
 33
 8034            foreach (var ch in uniqueChars)
 2535            {
 2536                if (!charToWordIndexDictionary.TryGetValue(ch, out var value))
 1437                {
 1438                    value = [];
 1439                    charToWordIndexDictionary[ch] = value;
 1440                }
 41
 2542                value.Add(i);
 2543            }
 1044        }
 45
 346        return charToWordIndexDictionary.TryGetValue(x, out var indices) ? indices : [];
 347    }
 48}