< Summary

Information
Class: LeetCode.Algorithms.FindTheNumberOfWaysToPlacePeople2.FindTheNumberOfWaysToPlacePeople2SortingGreedy
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\FindTheNumberOfWaysToPlacePeople2\FindTheNumberOfWaysToPlacePeople2SortingGreedy.cs
Line coverage
100%
Covered lines: 24
Uncovered lines: 0
Coverable lines: 24
Total lines: 61
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
NumberOfPairs(...)100%88100%
PointsComparison(...)100%22100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\FindTheNumberOfWaysToPlacePeople2\FindTheNumberOfWaysToPlacePeople2SortingGreedy.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.FindTheNumberOfWaysToPlacePeople2;
 13
 14/// <inheritdoc />
 15public class FindTheNumberOfWaysToPlacePeople2SortingGreedy : IFindTheNumberOfWaysToPlacePeople2
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n^2)
 19    ///     Space complexity - O(log n)
 20    /// </summary>
 21    /// <param name="points"></param>
 22    /// <returns></returns>
 23    public int NumberOfPairs(int[][] points)
 624    {
 625        Array.Sort(points, PointsComparison);
 26
 627        var n = points.Length;
 28
 629        var numberOfPairs = 0;
 30
 4831        for (var i = n - 1; i >= 1; i--)
 1832        {
 1833            var y1 = points[i][1];
 34
 1835            var minY = int.MaxValue;
 36
 11637            for (var j = i - 1; j >= 0; j--)
 4038            {
 4039                var y2 = points[j][1];
 40
 4041                if (y2 < y1 || y2 >= minY)
 2242                {
 2243                    continue;
 44                }
 45
 1846                minY = y2;
 47
 1848                numberOfPairs++;
 1849            }
 1850        }
 51
 652        return numberOfPairs;
 653    }
 54
 55    private static int PointsComparison(int[] a, int[] b)
 3956    {
 3957        var xComparison = a[0].CompareTo(b[0]);
 58
 3959        return xComparison == 0 ? b[1].CompareTo(a[1]) : xComparison;
 3960    }
 61}