< Summary

Information
Class: LeetCode.Algorithms.FindTheMinimumAreaToCoverAllOnes1.FindTheMinimumAreaToCoverAllOnes1OnePass
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\FindTheMinimumAreaToCoverAllOnes1\FindTheMinimumAreaToCoverAllOnes1OnePass.cs
Line coverage
94%
Covered lines: 35
Uncovered lines: 2
Coverable lines: 37
Total lines: 71
Line coverage: 94.5%
Branch coverage
93%
Covered branches: 15
Total branches: 16
Branch coverage: 93.7%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
MinimumArea(...)93.75%161694.59%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\FindTheMinimumAreaToCoverAllOnes1\FindTheMinimumAreaToCoverAllOnes1OnePass.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.FindTheMinimumAreaToCoverAllOnes1;
 13
 14/// <inheritdoc />
 15public class FindTheMinimumAreaToCoverAllOnes1OnePass : IFindTheMinimumAreaToCoverAllOnes1
 16{
 17    /// <summary>
 18    ///     Time complexity - O(m * n)
 19    ///     Space complexity - O(1)
 20    /// </summary>
 21    /// <param name="grid"></param>
 22    /// <returns></returns>
 23    public int MinimumArea(int[][] grid)
 524    {
 525        var m = grid.Length;
 526        var n = grid[0].Length;
 27
 528        var top = m;
 529        var bottom = -1;
 530        var left = n;
 531        var right = -1;
 32
 4433        for (var i = 0; i < m; i++)
 1734        {
 16835            for (var j = 0; j < n; j++)
 6736            {
 6737                if (grid[i][j] == 0)
 5638                {
 5639                    continue;
 40                }
 41
 1142                if (i < top)
 543                {
 544                    top = i;
 545                }
 46
 1147                if (i > bottom)
 948                {
 949                    bottom = i;
 950                }
 51
 1152                if (j < left)
 853                {
 854                    left = j;
 855                }
 56
 1157                if (j > right)
 758                {
 759                    right = j;
 760                }
 1161            }
 1762        }
 63
 564        if (bottom < 0)
 065        {
 066            return 0;
 67        }
 68
 569        return (right - left + 1) * (bottom - top + 1);
 570    }
 71}

Methods/Properties

MinimumArea(System.Int32[][])