Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Custom Stack Implementation

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Custom Stack Implementation. Start with the requirements on the right.

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.

Problem

How would you implement a custom Stack using basic array structures? What corner cases must you account for?

Implement process_stack(capacity, operations) using a fixed-size Python list, without relying on Python list methods such as append() or pop() for stack behavior. Each operation is ['push', value], ['pop'], ['peek'], or ['size']; return one result per operation: True or False for pushes, the removed or viewed value for pop and peek, None when those operations target an empty stack, and the current integer size for size.

Constraints

  • 1 <= capacity <= 10^5
  • 1 <= operations.length <= 10^5
  • Each operation is a valid push, pop, peek, or size command
  • Push values are integers

Function Signature

def process_stack(capacity, operations):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output