Design a Stack With Increment Operation LeetCode solution in Java
1class CustomStack {23int[] stack;4int top;56public CustomStack(int maxSize) {78// intialise the stack and the top9stack = new int[maxSize];10top = -1;11}1213public void push(int x) {1415// if the stack is full just skip16if (top == stack.length - 1) return;1718// add to the stack19top++;20stack[top] = x;21}2223public int pop() {2425// if stack is empty return -126if (top == -1) return -1;2728// remove/pop the top element29top--;30return stack[top + 1];31}3233public void increment(int k, int val) {3435// got to increment the min of the elements present in the stack and k36int n = Math.min(top + 1, k);3738for (int i = 0; i < n; i++) {39stack[i] += val;40}41}42}