Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Coding: Stack And Queue
00:00
5 left

Coding: Stack And Queue

EasyPython

Problem

During processing of JPMorganChase payment operations, implement two independent data structures. The first is a stack supporting constant-time minimum lookup. The second is a FIFO queue implemented using two stacks.

Write one function that processes both operation lists and returns their observable results.

Formal Specification

Implement solve_stack_queue_tasks(stack_ops, queue_ops):

  1. stack_ops is a list of operations in the form ["push", value], ["pop"], or ["get_min"]. Return the values produced by every pop and get_min, in order.
  2. queue_ops is a list of operations in the form ["enqueue", value], ["dequeue"], or ["peek"]. Return the values produced by every dequeue and peek, in order.
  3. Return a dictionary with keys "stack" and "queue".
  4. Operations that remove or inspect an empty structure will not appear in valid input.

Constraints

  • 1 <= len(stack_ops), len(queue_ops) <= 10^5
  • Values are integers in [-10^9, 10^9]
  • Each operation is valid for the current structure state
  • Operation names are exactly push, pop, get_min, enqueue, dequeue, or peek

Function Signature

def solve_stack_queue_tasks(stack_ops, queue_ops):
Interviewer

Your question is Coding: Stack And Queue. 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.