A bit longer advice! :P To initialize your vector, place it outside in the global

A bit longer advice! :stuck_out_tongue:
To initialize your vector, place it outside in the global scope, and as akshay mane said call vector.clear() insie the constructor.
something like this
/*
vector vec;
vector mins;
MinStack::MinStack()
{
vec.clear();
mins.clear();
}
*/
it will save some of debugging time.

Thanks. This worked. but one question. the constructor basically intialises our variables when object of that class is made. clearing memory in constructor makes no sense. its like . i make an object of my class. and the constructor is just clearing memory. then if i call push or something, how is it working??

Dear Utsav Prabhakar, this works because constructor is called only once when the object is initialized inside main, after that when using various funcitons of the MinStack class, the constructor is not called again and again but rather the memory persists in the global variable.

But what this does imply is that only one instance(object) of the MinStack class can exist(function reliably) at a time since all objects of this class will be sharing the same memory location.

Thank You sir for the advise. After following your advise, I feel confident for my placements,

Click here to start solving coding interview questions