< Summary

Information
Class: LeetCode.Algorithms.SpecialArrayWithXElementsGreaterThanOrEqualX.SpecialArrayWithXElementsGreaterThanOrEqualXSorting
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\SpecialArrayWithXElementsGreaterThanOrEqualX\SpecialArrayWithXElementsGreaterThanOrEqualXSorting.cs
Line coverage
92%
Covered lines: 12
Uncovered lines: 1
Coverable lines: 13
Total lines: 42
Line coverage: 92.3%
Branch coverage
87%
Covered branches: 7
Total branches: 8
Branch coverage: 87.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
SpecialArray(...)87.5%8892.3%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\SpecialArrayWithXElementsGreaterThanOrEqualX\SpecialArrayWithXElementsGreaterThanOrEqualXSorting.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.SpecialArrayWithXElementsGreaterThanOrEqualX;
 13
 14/// <inheritdoc />
 15public class SpecialArrayWithXElementsGreaterThanOrEqualXSorting : ISpecialArrayWithXElementsGreaterThanOrEqualX
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n log n)
 19    ///     Space complexity - O(1)
 20    /// </summary>
 21    /// <param name="nums"></param>
 22    /// <returns></returns>
 23    public int SpecialArray(int[] nums)
 324    {
 325        Array.Sort(nums);
 26
 1427        for (var i = 0; i < nums.Length; i++)
 628        {
 629            if (nums[i] < nums.Length - i)
 430            {
 431                continue;
 32            }
 33
 234            if (i == 0 || nums[i - 1] < nums.Length - i)
 235            {
 236                return nums.Length - i;
 37            }
 038        }
 39
 140        return -1;
 341    }
 42}

Methods/Properties

SpecialArray(System.Int32[])