Ans : 24 bytes.
STACK-MAX supports an operation “max( )” that reports the current maximum among all elements in the stack. Keeping this in mind, lets unfold the problem.
PUSH 5, STACK :
5
PUSH 6, STACK :
6
5
PUSH 7, STACK :
7
6
5
POP, STACK :
6
5
MAX, (In order to find the maximum element in the stack we have go through the entire STACK {O(n)}. So, we would need another stack STACK2. We would POP all the elements of STACK one by one and PUSH them to STACK2. In the process, we capture the maximum element and return it at the end of max() function)
2 elements would be present at STACK2 at this point temporarily and again PUSHed back to STACK to get back the original stack. .............(i)
PUSH 6, STACK :
6
6
5
PUSH 8, STACK :
8
6
6
5
(This is the maximum number of elements that can be present in STACK at a given time) .......(ii)
POP, STACK :
6
6
5
POP, STACK :
6
5
MAX .........same as (i)
From (i) and (ii), the maximum number of elements that can be present in STACK = 4 ;
the maximum number of elements that can be present in STACK2 = 2
So, data structure STACK_MAX should contain STACK and STACK2. Size of STACK_MAX = (4+2)*4 bytes = 24 bytes