< Summary

Information
Class: LeetCode.Algorithms.CountElementsWithStrictlySmallerAndGreaterElements.CountElementsWithStrictlySmallerAndGreaterElementsIterative
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\CountElementsWithStrictlySmallerAndGreaterElements\CountElementsWithStrictlySmallerAndGreaterElementsIterative.cs
Line coverage
84%
Covered lines: 11
Uncovered lines: 2
Coverable lines: 13
Total lines: 42
Line coverage: 84.6%
Branch coverage
83%
Covered branches: 5
Total branches: 6
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
CountElements(...)83.33%6684.61%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\CountElementsWithStrictlySmallerAndGreaterElements\CountElementsWithStrictlySmallerAndGreaterElementsIterative.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.CountElementsWithStrictlySmallerAndGreaterElements;
 13
 14/// <inheritdoc />
 15public class CountElementsWithStrictlySmallerAndGreaterElementsIterative :
 16    ICountElementsWithStrictlySmallerAndGreaterElements
 17{
 18    /// <summary>
 19    ///     Time complexity - O(n)
 20    ///     Space complexity - O(1)
 21    /// </summary>
 22    /// <param name="nums"></param>
 23    /// <returns></returns>
 24    public int CountElements(int[] nums)
 225    {
 226        if (nums.Length < 3)
 027        {
 028            return 0;
 29        }
 30
 231        var min = int.MaxValue;
 232        var max = int.MinValue;
 33
 2234        foreach (var num in nums)
 835        {
 836            min = Math.Min(min, num);
 837            max = Math.Max(max, num);
 838        }
 39
 1040        return nums.Count(num => num > min && num < max);
 241    }
 42}

Methods/Properties

CountElements(System.Int32[])