< Summary

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

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
CountGoodTriplets(...)100%1212100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\CountGoodTriplets\CountGoodTripletsBruteForce.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.CountGoodTriplets;
 13
 14/// <inheritdoc />
 15public class CountGoodTripletsBruteForce : ICountGoodTriplets
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n^3)
 19    ///     Space complexity - O(1)
 20    /// </summary>
 21    /// <param name="arr"></param>
 22    /// <param name="a"></param>
 23    /// <param name="b"></param>
 24    /// <param name="c"></param>
 25    /// <returns></returns>
 26    public int CountGoodTriplets(int[] arr, int a, int b, int c)
 227    {
 228        var result = 0;
 29
 1830        for (var i = 0; i < arr.Length - 2; i++)
 731        {
 4632            for (var j = i + 1; j < arr.Length - 1; j++)
 1633            {
 1634                if (Math.Abs(arr[i] - arr[j]) > a)
 735                {
 736                    continue;
 37                }
 38
 6039                for (var k = j + 1; k < arr.Length; k++)
 2140                {
 2141                    if (Math.Abs(arr[j] - arr[k]) <= b &&
 2142                        Math.Abs(arr[i] - arr[k]) <= c)
 443                    {
 444                        result++;
 445                    }
 2146                }
 947            }
 748        }
 49
 250        return result;
 251    }
 52}