This is a typical interview question which is going to ask you to implement a stack
which can track the max/min value for the current stack. The solution posted here will only show how min-stack is implemented, and max-stack can be developed similarly.
require'pry'require'pp'classStackattr_reader:stackdefinitialize@stack=[]enddefpop@stack.popenddefpush(element)@stack.push(element)enddefpeek@stack[-1]endendclassMinStackattr_reader:min_stack,:stackdefinitialize@min_stack=Stack.new@stack=Stack.newenddefpush(element)if@stack.peek&&@stack.peek<element@min_stack.push(@stack.peek)else@min_stack.push(element)end@stack.push(element)enddefpop@stack.popputs"The minimun is #{@min_stack.pop}"endendmin_stack=MinStack.newmin_stack.push(2)min_stack.push(5)