BackmediumArrays Atlassian Oracle

Alternating Maximum Minimum Stack Operation Solution

Problem Statement

You are given an array of integers `arr` and an integer `k` representing the number of operations. Implement a data structure that supports two operations: pushing elements onto the stack and popping elements from the stack, such that the maximum and minimum elements alternate at the top of the stack. After `k` operations, return the top element of the stack.

Constraints

  • Input array may contain any integer values between -1,000,000 and 1,000,000.
  • Input array may contain zeros, but there will be at least one non-zero element.
  • Maximum size of the array is 100,000 elements.
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free