< Summary

Information
Class: LeetCode.Algorithms.SpiralMatrix3.SpiralMatrix3Simulation
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\SpiralMatrix3\SpiralMatrix3Simulation.cs
Line coverage
100%
Covered lines: 39
Uncovered lines: 0
Coverable lines: 39
Total lines: 82
Line coverage: 100%
Branch coverage
95%
Covered branches: 21
Total branches: 22
Branch coverage: 95.4%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
SpiralMatrixIII(...)95.45%2222100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\SpiralMatrix3\SpiralMatrix3Simulation.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.SpiralMatrix3;
 13
 14/// <inheritdoc />
 15public class SpiralMatrix3Simulation : ISpiralMatrix3
 16{
 17    /// <summary>
 18    ///     Time complexity - O(rows x cols)
 19    ///     Space complexity - O(rows x cols)
 20    /// </summary>
 21    /// <param name="rows"></param>
 22    /// <param name="cols"></param>
 23    /// <param name="rStart"></param>
 24    /// <param name="cStart"></param>
 25    /// <returns></returns>
 26    public int[][] SpiralMatrixIII(int rows, int cols, int rStart, int cStart)
 227    {
 228        var result = new int[rows * cols][];
 29
 230        var direction = 0;
 231        var directionCounter = 1;
 232        var directionCount = -1;
 233        var i = 0;
 34
 10035        while (i < result.Length)
 9836        {
 9837            if (rStart >= 0 && cStart >= 0 && rStart < rows && cStart < cols)
 3438            {
 3439                result[i] = [rStart, cStart];
 40
 3441                i++;
 3442            }
 43
 9844            directionCount++;
 45
 9846            if (directionCount >= directionCounter)
 2447            {
 2448                directionCount = 0;
 49
 2450                direction++;
 51
 2452                if (direction > 0 && direction % 2 == 0)
 1153                {
 1154                    directionCounter++;
 1155                }
 56
 2457                if (direction > 3)
 558                {
 559                    direction = 0;
 560                }
 2461            }
 62
 9863            switch (direction)
 64            {
 65                case 0:
 2566                    cStart++;
 2567                    break;
 68                case 1:
 2369                    rStart++;
 2370                    break;
 71                case 2:
 2672                    cStart--;
 2673                    break;
 74                default:
 2475                    rStart--;
 2476                    break;
 77            }
 9878        }
 79
 280        return result;
 281    }
 82}