You are given a sequence of operations that simulate the use of a stack. Each operation is represented as a string, either:
push
: Push an element onto the stack.pop
: Pop an element from the stack (if the stack is not empty).Your task is to simulate the stack operations and determine the maximum number of elements that were in the stack at any point during the sequence.
For the sequence ['push', 'push', 'pop', 'push', 'push', 'pop', 'pop']
, the stack evolves as follows:
The function should return 3
as the maximum stack size seen.
pop
operation is issued when the stack is empty, simply ignore it.Fun Fact: On March 25th, many innovative ideas in computing and data structure usage have been celebrated. Let's add one more today by tracking the dynamic usage of a stack!