Not working for some test cases


#1

vector v;
//int minx=INT_MAX;
//set s;
MinStack::MinStack() {
}

void MinStack::push(int x) {
v.push_back(x);
//if(x < minx)minx=x;
}

void MinStack::pop() {
if(v.size()==0)return ;
v.pop_back();
}

int MinStack::top() {
if(v.size()==0)return -1;
return v[v.size()-1];
}

int MinStack::getMin() {
if(v.size()==0)return -1;
return *min_element(v.begin(),v.end());
}


#2

That is because you are not clearing your global variable. Write v.clear() in constructor and it will work.
But anyway this would not earn you full points because it needs to be done in constant time and *min_element takes O(n) time.