< 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) 2026 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 sealed class DesignStackWithIncrementOperationArray : IDesignStackWithIncrementOperation
 16{
 17    private readonly int[] _stackArray;
 518    private int _topIndex = -1;
 19
 520    public DesignStackWithIncrementOperationArray(int maxSize)
 521    {
 522        _stackArray = new int[maxSize];
 523    }
 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)
 1231    {
 1232        if (_topIndex >= _stackArray.Length - 1)
 233        {
 234            return;
 35        }
 36
 1037        _topIndex++;
 38
 1039        _stackArray[_topIndex] = x;
 1240    }
 41
 42    /// <summary>
 43    ///     Time complexity - O(1)
 44    ///     Space complexity - O(1)
 45    /// </summary>
 46    /// <returns></returns>
 47    public int Pop()
 1348    {
 1349        if (_topIndex < 0)
 350        {
 351            return -1;
 52        }
 53
 1054        return _stackArray[_topIndex--];
 1355    }
 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)
 464    {
 2265        for (var i = 0; i < Math.Min(k, _topIndex + 1); i++)
 766        {
 767            _stackArray[i] += val;
 768        }
 469    }
 70}