edited by
2,967 views
9 votes
9 votes

How it is 24? I'm not getting it.

edited by

5 Answers

0 votes
0 votes

Ans: 20 bytes

Applying efficient algorithm, 

Main_Stack Max_Stack
5  
8 8
6  
7 7
6 6
5 5

Here, when 7 is pushed, new entry is created in MAX_STACK because it is the new MAX. 

Next element to be pushed is 6. Applying efficient algorithm there is no need to push it in MAX_STACK. 

Similarly, when 8 is pushed, new entry is created in MAX_STACK of new MAX.

Now, coming to POP peration, 8,6,7 are popped from MAIN_STACK and along with it 8 and 7 are also popped from MAX_STACK.

At the end, 5 is pushed on MAIN_STACK and no need to insert it on MAX_STACK.

So, final table is - 

MAIN_STACK MAX_STACK
5  
6 6
5 5

So, total number of elements = 5

Total size = 5*4 bytes = 20 Bytes

PS : Above concept is discussed in Data Structures and Algorithms - Narasimha Karumanchi 

edited by
Answer:

Related questions

2 votes
2 votes
2 answers
4
jatin khachane 1 asked Dec 1, 2018
1,225 views
My doubt : What should we consider ^ operator as Bitwise XOR ? or Exponentiation