Correct test case in testing, garbage on submitting for test case "586 g t t g P 593848644 t p t t t t p P 680232627 P 383101258..."


#1

For the test case “586 g t t g P 593848644 t p t t t t p P 680232627 P 383101258…”, it is showing that my function is returning garbage value but when I ran it as custom test, the output was matching the expected output. Moderators, please look into it!


#2

Yep. I’m also facing the same problem. I’m using Python2.


#3

Yes,I am also face the same issue.I am using C++


#4

the stack which u declare as globle clear it after the program exection


#5

For this test case, there are two things because of which this test case fails:

  1. not clearing global variables
  2. using top or pop functions on empty stack

Happy Coding :slight_smile:


#6

NOTE:
i) When the top of stack is less than min Element you have to return min Element.
( as u would have stored it as stack.push(2*x - current min element) )
ii) Empty stack in the constructor and reset min Element to -1;
iii) Before returning the min Element or top of stack always check if stack is not empty.
iv) Check if stack is empty after poping and set min Element to -1 in that case.
Happy coding :slight_smile:


#7

Just resize the array as zero size in the constructor, it would work fine, idk maybe it’s intializing it with some garbage values!


#8

Are you initializing min variable with INT_MAX. If yes do not initialize it, rather use a separate condition in push function like this:
if(s.size()==0){
s.push(a);
mn=a;
}
It worked for me.


#9

after declaration of stack ,empty the stack in constructor as shown .it worked for me…happy coding
stacks;
MinStack::MinStack() {
while(s.size()){
s.pop();
}
}