< Summary

Information
Class: LeetCode.Algorithms.DesignStackWithIncrementOperation.DesignStackWithIncrementOperationArray
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\DesignStackWithIncrementOperation\DesignStackWithIncrementOperationArray.cs
Line coverage
100%
Covered lines: 24
Uncovered lines: 0
Coverable lines: 24
Total lines: 70
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
.ctor(...)100%11100%
Push(...)100%22100%
Pop()100%22100%
Increment(...)100%22100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\DesignStackWithIncrementOperation\DesignStackWithIncrementOperationArray.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.DesignStackWithIncrementOperation;
 13
 14/// <inheritdoc />
 15public class DesignStackWithIncrementOperationArray : IDesignStackWithIncrementOperation
 16{
 17    private readonly int[] _stackArray;
 118    private int _topIndex = -1;
 19
 120    public DesignStackWithIncrementOperationArray(int maxSize)
 121    {
 122        _stackArray = new int[maxSize];
 123    }
 24
 25    /// <summary>
 26    ///     Time complexity - O(1)
 27    ///     Space complexity - O(1)
 28    /// </summary>
 29    /// <param name="x"></param>
 30    public void Push(int x)
 531    {
 532        if (_topIndex >= _stackArray.Length - 1)
 133        {
 134            return;
 35        }
 36
 437        _topIndex++;
 38
 439        _stackArray[_topIndex] = x;
 540    }
 41
 42    /// <summary>
 43    ///     Time complexity - O(1)
 44    ///     Space complexity - O(1)
 45    /// </summary>
 46    /// <returns></returns>
 47    public int Pop()
 548    {
 549        if (_topIndex < 0)
 150        {
 151            return -1;
 52        }
 53
 454        return _stackArray[_topIndex--];
 555    }
 56
 57    /// <summary>
 58    ///     Time complexity - O(min(k,n))
 59    ///     Space complexity - O(1)
 60    /// </summary>
 61    /// <param name="k"></param>
 62    /// <param name="val"></param>
 63    public void Increment(int k, int val)
 264    {
 1465        for (var i = 0; i < Math.Min(k, _topIndex + 1); i++)
 566        {
 567            _stackArray[i] += val;
 568        }
 269    }
 70}