Design a stack which supports the following operations.
Implement the CustomStack class:
1: void push(int x) Adds x to the top of the stack if the stack hasn't reached the maxSize.
2: int pop() Pops and returns the top of stack or -1 if the stack is empty.
3: void inc(int k, int val) Increments the bottom k elements of the stack by val. If there are less than k elements in the stack, just increment all the elements in the stack.
Input Format
Input is managed for you
Output Format
Output is managed for you
Constraints
1: 1 <= maxSize <= 1000 2: 1 <= x <= 1000 3: 1 <= k <= 1000 4: 0 <= val <= 100 5: At most 1000 calls will be made to each method of increment, push and pop each separately.
Notice
Try First, Check Solution later
1. You should first read the question and watch the question video.2. Think of a solution approach, then try and submit the question on editor tab.3. We strongly advise you to watch the solution video for prescribed approach.Example
Input
3 push 1 push 2 pop push 2 push 3 push 4 increment 5 100 increment 2 100 pop pop pop pop exit
Output
2 103 202 201 -1 exit