class CustomStack:
def __init__(self, maxSize: int):
pass
def push(self, x: int) -> None:
pass
def pop(self) -> int:
pass
def increment(self, k: int, val: int) -> None:
passclass CustomStack {
public CustomStack(int maxSize) {
// constructor
}
public void push(int x) {
// push method
}
public int pop() {
// pop method
return 0;
}
public void increment(int k, int val) {
// increment method
}
}class CustomStack {
public:
CustomStack(int maxSize) {
// constructor
}
void push(int x) {
// push method
}
int pop() {
// pop method
return 0;
}
void increment(int k, int val) {
// increment method
}
};class CustomStack {
constructor(maxSize) {
// constructor
}
push(x) {
// push method
}
pop() {
// pop method
return -1;
}
increment(k, val) {
// increment method
}
}
class CustomStack:
def __init__(self, maxSize: int):
# Write your solution here
pass
def push(self, x: int) -> None:
pass
def pop(self) -> int:
pass
def increment(self, k: int, val: int) -> None:
pass
class CustomStack {
public CustomStack(int maxSize) {
// Write your solution here
}
public void push(int x) {
// Write your solution here
}
public int pop() {
// Write your solution here
return -1;
}
public void increment(int k, int val) {
// Write your solution here
}
}
#include <vector>
using namespace std;
class CustomStack {
public:
CustomStack(int maxSize) {
// Write your solution here
}
void push(int x) {
// Write your solution here
}
int pop() {
// Write your solution here
return -1;
}
void increment(int k, int val) {
// Write your solution here
}
};
class CustomStack {
constructor(maxSize) {
// Write your solution here
}
push(x) {
// Write your solution here
}
pop() {
// Write your solution here
return -1;
}
increment(k, val) {
// Write your solution here
}
}
Common Bugs to Avoid
Wrong: Pop returns incorrect values after increment callsIncrement applied incorrectly to top elements or all elements instead of bottom k elements✅ Apply increment only to bottom min(k, stack size) elements in the increment method
Wrong: Pop returns -1 even when stack is not emptyPop method does not check if stack is empty before popping✅ Add check if stack is empty before popping and return -1 if empty
Wrong: Push allows more elements than maxSizePush method does not check current stack size before pushing✅ Check if stack size < maxSize before pushing new element
Wrong: Increment calls overwrite previous increments instead of accumulatingIncrement method resets increments instead of adding to existing increments✅ Add increments cumulatively to auxiliary increments array or directly to elements
Wrong: Solution times out on large inputsBrute force increment implementation with O(n*k) complexity✅ Implement lazy increment approach using auxiliary array to achieve O(n) total time