Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
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
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess 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
Build my plan
Stack Implementation
00:00
5 left

Stack Implementation

EasyPython

Problem

A 24]7.ai conversation workflow needs a last-in, first-out history of event identifiers so the most recent event can be inspected or removed first. Implement the stack behavior for a sequence of operations.

Create a function that processes operations in order:

  1. push(value) adds value to the top of the stack and produces no output.
  2. pop() removes and returns the top value.
  3. top() returns the top value without removing it.

The input is represented as a list of operation arrays. A push operation has the form ["push", value]; pop and top operations have the form ["pop"] and ["top"]. Return a list containing results from pop and top operations in their original order. Do not include output for push operations.

Formal Specification

Given operations, a list of operation arrays containing integer values, return a list of integers produced by pop and top. The input guarantees that pop and top are never called when the stack is empty.

Constraints

  • 1 <= len(operations) <= 10^5
  • Values are integers in [-10^9, 10^9]
  • Every operation is valid
  • The operation name is one of push, pop, or top

Function Signature

def process_stack(operations):
Interviewer

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