Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Min Stack and Similar LeetCode Task
00:00
5 left

Min Stack and Similar LeetCode Task

EasyPython

Problem

The CarGurus search experience may process a stream of numeric listing scores or prices while needing to inspect the current minimum efficiently. Implement a stack that supports standard stack operations and retrieves its minimum value in O(1) time.

Create process_min_stack(operations), where each operation is represented as an array:

  • ["push", value] adds an integer to the stack.
  • ["pop"] removes and returns the top value.
  • ["top"] returns the top value without removing it.
  • ["getMin"] returns the smallest value currently in the stack.

For push operations, append null to the result. The input will not call pop, top, or getMin when the stack is empty.

Constraints

  • 1 <= operations.length <= 10^5
  • Each pushed value is an integer in [-10^9, 10^9]
  • Every pop, top, and getMin operation occurs while the stack is non-empty
  • Duplicate values may appear in the stack
  • Operation names are valid

Function Signature

def process_min_stack(operations):
Interviewer

Your question is Min Stack and Similar LeetCode Task. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.