< Summary

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

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
CheckArithmeticSubarrays(...)100%66100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\ArithmeticSubarrays\ArithmeticSubarraysSort.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.ArithmeticSubarrays;
 13
 14/// <inheritdoc />
 15public class ArithmeticSubarraysSort : IArithmeticSubarrays
 16{
 17    /// <summary>
 18    ///     Time complexity - O(m * n log n)
 19    ///     Space complexity - O(n)
 20    /// </summary>
 21    /// <param name="nums"></param>
 22    /// <param name="l"></param>
 23    /// <param name="r"></param>
 24    /// <returns></returns>
 25    public IList<bool> CheckArithmeticSubarrays(int[] nums, int[] l, int[] r)
 626    {
 627        var result = new bool[l.Length];
 28
 4829        for (var i = 0; i < l.Length; i++)
 1830        {
 1831            var subArrayLength = r[i] - l[i] + 1;
 32
 1833            var subArray = new int[subArrayLength];
 34
 15635            for (var j = 0; j < subArrayLength; j++)
 6036            {
 6037                subArray[j] = nums[l[i] + j];
 6038            }
 39
 1840            Array.Sort(subArray);
 41
 1842            var diff = subArray[1] - subArray[0];
 43
 1844            var currentResult = true;
 45
 8446            for (var j = 2; j < subArray.Length; j++)
 2447            {
 2448                currentResult &= subArray[j] - subArray[j - 1] == diff;
 2449            }
 50
 1851            result[i] = currentResult;
 1852        }
 53
 654        return result;
 655    }
 56}