Paparazzi Stacked To The Max - Silver - Hammered Bars - Bangle Like Cu
Given a Stack, keep track of the maximum value in it. The maximum value may be the top element of the stack, but once a new element is pushed or an element is popped from the stack, the maximum element will be now from the rest of the elements. Method 1 Brute-force : We keep pushing the elements in the main stack and whenever we are asked to return the maximum element, we traverse the stack and print the max element. Method 2 Efficient : An efficient approach would be to maintain an auxiliary stack while pushing element in the main stack.