< Summary

Information
Class: LeetCode.Algorithms.TwoOutOfThree.TwoOutOfThreeFrequencyDictionary
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\TwoOutOfThree\TwoOutOfThreeFrequencyDictionary.cs
Line coverage
87%
Covered lines: 21
Uncovered lines: 3
Coverable lines: 24
Total lines: 58
Line coverage: 87.5%
Branch coverage
93%
Covered branches: 15
Total branches: 16
Branch coverage: 93.7%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
TwoOutOfThree(...)93.75%171687.5%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\TwoOutOfThree\TwoOutOfThreeFrequencyDictionary.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.TwoOutOfThree;
 13
 14/// <inheritdoc />
 15public class TwoOutOfThreeFrequencyDictionary : ITwoOutOfThree
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n)
 19    ///     Space complexity - O(n)
 20    /// </summary>
 21    /// <param name="nums1"></param>
 22    /// <param name="nums2"></param>
 23    /// <param name="nums3"></param>
 24    /// <returns></returns>
 25    public IList<int> TwoOutOfThree(int[] nums1, int[] nums2, int[] nums3)
 326    {
 327        var frequencyDictionary = new Dictionary<int, int>();
 28
 1629        foreach (var num1 in new HashSet<int>(nums1).Where(num1 => !frequencyDictionary.TryAdd(num1, 1)))
 030        {
 031            frequencyDictionary[num1]++;
 032        }
 33
 2134        foreach (var num2 in new HashSet<int>(nums2).Where(num2 => !frequencyDictionary.TryAdd(num2, 1)))
 335        {
 336            frequencyDictionary[num2]++;
 337        }
 38
 1939        foreach (var num3 in new HashSet<int>(nums3).Where(num3 => !frequencyDictionary.TryAdd(num3, 1)))
 340        {
 341            frequencyDictionary[num3]++;
 342        }
 43
 344        var result = new List<int>();
 45
 3146        foreach (var frequency in frequencyDictionary)
 1147        {
 1148            if (frequency.Value < 2)
 649            {
 650                continue;
 51            }
 52
 553            result.Add(frequency.Key);
 554        }
 55
 356        return result;
 357    }
 58}