< Summary

Information
Class: LeetCode.Algorithms.SmallestPairWithDifferentFrequencies.SmallestPairWithDifferentFrequenciesLookup
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\SmallestPairWithDifferentFrequencies\SmallestPairWithDifferentFrequenciesLookup.cs
Line coverage
100%
Covered lines: 37
Uncovered lines: 0
Coverable lines: 37
Total lines: 74
Line coverage: 100%
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
.cctor()100%11100%
MinDistinctFreqPair(...)93.75%1616100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\SmallestPairWithDifferentFrequencies\SmallestPairWithDifferentFrequenciesLookup.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.SmallestPairWithDifferentFrequencies;
 13
 14/// <inheritdoc />
 15public sealed class SmallestPairWithDifferentFrequenciesLookup : ISmallestPairWithDifferentFrequencies
 16{
 117    private static readonly int[] EmptyPair = [-1, -1];
 18
 19    /// <summary>
 20    ///     Time complexity - O(n)
 21    ///     Space complexity - O(1)
 22    /// </summary>
 23    /// <param name="nums"></param>
 24    /// <returns></returns>
 25    public int[] MinDistinctFreqPair(int[] nums)
 326    {
 327        if (nums.Length < 3)
 228        {
 229            return EmptyPair;
 30        }
 31
 132        Span<int> frequencies = stackalloc int[101];
 33
 1434        for (var i = 0; i < nums.Length; i++)
 635        {
 636            var num = nums[i];
 37
 638            frequencies[num]++;
 639        }
 40
 141        var xFrequency = 0;
 142        var x = -1;
 143        var y = -1;
 44
 1045        for (var i = 0; i < frequencies.Length; i++)
 546        {
 547            var frequency = frequencies[i];
 48
 549            if (frequency <= 0)
 150            {
 151                continue;
 52            }
 53
 454            if (x < 0)
 155            {
 156                x = i;
 157                xFrequency = frequency;
 158            }
 359            else if (y < 0)
 260            {
 261                if (frequency != xFrequency)
 162                {
 163                    y = i;
 164                }
 265            }
 66            else
 167            {
 168                break;
 69            }
 370        }
 71
 172        return y == -1 ? EmptyPair : [x, y];
 373    }
 74}