Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Get started
Coding: Stack And Queue
00:00
5 left

Coding: Stack And Queue

MediumPython

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.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.