PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates competency in data structure design and algorithmic analysis, focusing on stack operations augmented with maximum-tracking and correctness when multiple maximal elements and ordering constraints are present.

  • medium
  • Zipline
  • Coding & Algorithms
  • Software Engineer

Implement a Maximum-Tracking Stack

Company: Zipline

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Design a stack-like data structure that supports the following operations efficiently: - `push(x)`: Push integer `x` onto the stack. - `pop()`: Remove and return the element at the top of the stack. - `top()`: Return the element at the top of the stack without removing it. - `peekMax()`: Return the maximum value currently in the stack without removing it. - `popMax()`: Remove and return the maximum value currently in the stack. If the maximum value appears multiple times, remove the occurrence closest to the top of the stack. Assume `pop`, `top`, `peekMax`, and `popMax` are only called when the stack is non-empty. Provide an optimal implementation and analyze the time complexity of each operation.

Quick Answer: This question evaluates competency in data structure design and algorithmic analysis, focusing on stack operations augmented with maximum-tracking and correctness when multiple maximal elements and ordering constraints are present.

Simulate push, pop, top, peekMax, and popMax; popMax removes the topmost maximum.

Examples

Input: ((('push', 5), ('push', 1), ('push', 5), ('top',), ('popMax',), ('top',), ('peekMax',), ('pop',), ('top',)),)

Expected Output: [5, 5, 1, 5, 1, 5]

Explanation: Standard MaxStack sequence.

Input: ((('push', 3), ('push', 3), ('popMax',), ('pop',)),)

Expected Output: [3, 3]

Explanation: Topmost maximum tie.

Last updated: Jun 27, 2026

Related Coding Questions

  • Compute Maximum Area Under Adjacent Bars - Zipline (medium)

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.