< Summary

Information
Class: LeetCode.Algorithms.NumberOfSubArraysWithOddSum.NumberOfSubArraysWithOddSumBruteForce
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\NumberOfSubArraysWithOddSum\NumberOfSubArraysWithOddSumBruteForce.cs
Line coverage
100%
Covered lines: 16
Uncovered lines: 0
Coverable lines: 16
Total lines: 46
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
NumOfSubarrays(...)100%66100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\NumberOfSubArraysWithOddSum\NumberOfSubArraysWithOddSumBruteForce.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.NumberOfSubArraysWithOddSum;
 13
 14/// <inheritdoc />
 15public class NumberOfSubArraysWithOddSumBruteForce : INumberOfSubArraysWithOddSum
 16{
 17    private const int Mod = (int)(1e9 + 7);
 18
 19    /// <summary>
 20    ///     Time complexity - O(n^2)
 21    ///     Space complexity - O(1)
 22    /// </summary>
 23    /// <param name="arr"></param>
 24    /// <returns></returns>
 25    public int NumOfSubarrays(int[] arr)
 326    {
 327        var count = 0;
 28
 3229        for (var i = 0; i < arr.Length; i++)
 1330        {
 1331            var currentSum = 0;
 32
 10633            for (var j = i; j < arr.Length; j++)
 4034            {
 4035                currentSum += arr[j];
 36
 4037                if (currentSum % 2 != 0)
 2038                {
 2039                    count++;
 2040                }
 4041            }
 1342        }
 43
 344        return count % Mod;
 345    }
 46}

Methods/Properties

NumOfSubarrays(System.Int32[])