On two occasions I have been asked [by members of Parliament]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question. Charles Babbage

Min and Max finding

Language Java | Level Intermediate | Category Algorithms | August 3, 2015 10:46 pm

Algorithm Problem Description

Write a function to find minimum and maximum value from the queue. You can use two stacks to store the values. Stack uses last in first out approach to push and pop elements.

Write a program to implement a queue with two stacks for finding minimum and maximum items using (1) time?



Items in the Stack: [12, 1, 12, 56, 78, 99]
Minimum item from the stack:1
Maximum item from the stack:99



Please login to add comments.