Skip to content

re: Finding Max in a Stack VIEW POST

re: Hi Beautus, Thank you for reading! I did implement the peek method in my stack to see the last value in the array. I'm not sure if I am underst...

No no, I do understand your solution fully. What I didn't make clear though is that my solution assumes that a stack is already hydrated when it gets the max value, and your solution is perfect for getting the max value without traversing the stack each time max is required. I'm not sure if you get me

Oh I see. I did misunderstand at first, I apologize for that. So your solution is a loop, but with pushing to a holding stack while comparing values? This also assumes that no new values are added to the stack. Am I understanding it correctly?

code of conduct - report abuse