< Summary

Information
Class: LeetCode.Algorithms.FindTargetIndicesAfterSortingArray.FindTargetIndicesAfterSortingArrayIterative
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\FindTargetIndicesAfterSortingArray\FindTargetIndicesAfterSortingArrayIterative.cs
Line coverage
100%
Covered lines: 21
Uncovered lines: 0
Coverable lines: 21
Total lines: 50
Line coverage: 100%
Branch coverage
100%
Covered branches: 8
Total branches: 8
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
TargetIndices(...)100%88100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\FindTargetIndicesAfterSortingArray\FindTargetIndicesAfterSortingArrayIterative.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.FindTargetIndicesAfterSortingArray;
 13
 14/// <inheritdoc />
 15public class FindTargetIndicesAfterSortingArrayIterative : IFindTargetIndicesAfterSortingArray
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n)
 19    ///     Space complexity - O(k)
 20    /// </summary>
 21    /// <param name="nums"></param>
 22    /// <param name="target"></param>
 23    /// <returns></returns>
 24    public IList<int> TargetIndices(int[] nums, int target)
 325    {
 326        var smallerCount = 0;
 327        var equalCount = 0;
 28
 3929        foreach (var num in nums)
 1530        {
 1531            if (num < target)
 832            {
 833                smallerCount++;
 834            }
 735            else if (num == target)
 436            {
 437                equalCount++;
 438            }
 1539        }
 40
 341        var result = new List<int>();
 42
 1443        for (var i = 0; i < equalCount; i++)
 444        {
 445            result.Add(smallerCount + i);
 446        }
 47
 348        return result;
 349    }
 50}