Can anyone please help me with the Algorithm for this problem (its an Interview Question):
You are given a stack. Devise an algorithm to find the maximum number
using PUSH/POP Operations only.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Given the lack of constraints in the original post, you can just pop off all the data and compute a running maximum:
Edit (with the new restriction that the original stack is unchanged and the new resource of a second available stack):