< Summary

Information
Class: LeetCode.Algorithms.MinimizeMaximumPairSumInArray.MinimizeMaximumPairSumInArrayCounting
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\MinimizeMaximumPairSumInArray\MinimizeMaximumPairSumInArrayCounting.cs
Line coverage
100%
Covered lines: 28
Uncovered lines: 0
Coverable lines: 28
Total lines: 65
Line coverage: 100%
Branch coverage
83%
Covered branches: 10
Total branches: 12
Branch coverage: 83.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
MinPairSum(...)83.33%1212100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\MinimizeMaximumPairSumInArray\MinimizeMaximumPairSumInArrayCounting.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.MinimizeMaximumPairSumInArray;
 13
 14/// <inheritdoc />
 15public sealed class MinimizeMaximumPairSumInArrayCounting : IMinimizeMaximumPairSumInArray
 16{
 17    private const int MaxValue = 100_000;
 18
 19    /// <summary>
 20    ///     Time complexity - O(n)
 21    ///     Space complexity - O()
 22    /// </summary>
 23    /// <param name="nums"></param>
 24    /// <returns></returns>
 25    public int MinPairSum(int[] nums)
 226    {
 227        Span<int> frequencies = stackalloc int[MaxValue + 1];
 28
 2629        foreach (var num in nums)
 1030        {
 1031            frequencies[num]++;
 1032        }
 33
 234        var left = 1;
 235        var right = MaxValue;
 36
 237        var result = 0;
 38
 239        var remaining = nums.Length;
 40
 741        while (remaining > 0)
 542        {
 1043            while (left <= right && frequencies[left] == 0)
 544            {
 545                left++;
 546            }
 47
 19999848            while (left <= right && frequencies[right] == 0)
 19999349            {
 19999350                right--;
 19999351            }
 52
 553            var sum = left + right;
 54
 555            result = Math.Max(result, sum);
 56
 557            frequencies[left]--;
 558            frequencies[right]--;
 59
 560            remaining -= 2;
 561        }
 62
 263        return result;
 264    }
 65}

Methods/Properties

MinPairSum(System.Int32[])