Design a stack that supports push
(x), pop(), top(), peekMax(), and popMax(). The popMax operation must remove and return the maximum element; if there are multiple maximums, remove the most recently pushed one. Implement two approaches:
(A) an amortized O(
-
solution using auxiliary structures, and
(B) an O(log n) popMax solution using a balanced tree or heap plus linked nodes. Explain how you will handle duplicates, empty-structure edge cases, and concurrency concerns for a high-throughput system. Provide time/space complexities and brief test cases.