Let max_size=0 represents the required size and curr_size is the current size of the stack.
Initially ( will push into stack now curr_size=1, as curr_size > max_size so max_size =1
now,( will push into stack now curr_size=2, as curr_size > max_size so max_size =2
Now, ) comes then pop() operation will perform so curr_size become 1 ,
Now ( will push into stack now curr_size=2, as curr_size > max_size so max_size =2
Now again ( will push into stack now curr_size=3, as curr_size > max_size so max_size =3
Now, ) comes then pop() operation will perform so curr_size become 2
Again ) comes then pop() operation will perform so curr_size become 1
Now ( will push into stack now curr_size=2, as curr_size > max_size so max_size =2
Now again ( will push into stack now curr_size=3, as curr_size > max_size so max_size =3
Now, ) comes then pop() operation will perform so curr_size become 2
Again ) comes then pop() operation will perform so curr_size become 1
And at last ) comes then pop() operation will perform so curr_size become 1
So the max_size appears to be 3.
Login/Signup to comment