Bloomberg L.P. Interview Question: Implement a Stack that suppor... | Glassdoor

Interview Question

Financial Software Developer Interview Baltimore, MD

Implement a Stack that supports a max function?

Answer

Interview Answer

1 Answer

0

Can be implemented by bundling two stacks - one for the actual stack and another one keeping the max seen so far.

Example: push sequence 1, 3, 2, 4, 4, 1, 5

[1] - [1]
[1, 3] - [1, 3]
[1, 3, 2] - [1, 3]
[1, 3, 2, 4] - [1, 3, 4]
[1, 3, 2, 4, 4] - [1, 3, 4, 4] (4 duplicate to be able to handle popping the stack)
[1, 3, 2, 4, 4, 1] - [1, 3, 4, 4]
[1, 3, 2, 4, 4, 1, 5] - [1, 3, 4, 4, 5]

Anonymous on Nov 2, 2016

Add Answers or Comments

To comment on this, Sign In or Sign Up.