< Summary

Information
Class: LeetCode.Algorithms.CheckIfArrayPairsAreDivisibleByK.CheckIfArrayPairsAreDivisibleByKTwoPointers
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\CheckIfArrayPairsAreDivisibleByK\CheckIfArrayPairsAreDivisibleByKTwoPointers.cs
Line coverage
100%
Covered lines: 28
Uncovered lines: 0
Coverable lines: 28
Total lines: 67
Line coverage: 100%
Branch coverage
100%
Covered branches: 10
Total branches: 10
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
CanArrange(...)100%1010100%
.ctor(...)100%11100%
Compare(...)100%11100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\CheckIfArrayPairsAreDivisibleByK\CheckIfArrayPairsAreDivisibleByKTwoPointers.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.CheckIfArrayPairsAreDivisibleByK;
 13
 14/// <inheritdoc />
 15public class CheckIfArrayPairsAreDivisibleByKTwoPointers : ICheckIfArrayPairsAreDivisibleByK
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n log n)
 19    ///     Space complexity - O(log n)
 20    /// </summary>
 21    /// <param name="arr"></param>
 22    /// <param name="k"></param>
 23    /// <returns></returns>
 24    public bool CanArrange(int[] arr, int k)
 825    {
 826        Array.Sort(arr, new Comparator(k));
 27
 828        var left = 0;
 829        var right = arr.Length - 1;
 30
 1331        while (left < right)
 1132        {
 1133            if (arr[left] % k != 0)
 534            {
 535                break;
 36            }
 37
 638            if (arr[left + 1] % k != 0)
 139            {
 140                return false;
 41            }
 42
 543            left += 2;
 544        }
 45
 1946        while (left < right)
 1347        {
 1348            if ((arr[left] + arr[right]) % k != 0)
 149            {
 150                return false;
 51            }
 52
 1253            left++;
 1254            right--;
 1255        }
 56
 657        return true;
 858    }
 59
 860    private class Comparator(int k) : IComparer<int>
 61    {
 62        public int Compare(int i, int j)
 6463        {
 6464            return ((k + (i % k)) % k) - ((k + (j % k)) % k);
 6465        }
 66    }
 67}