PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Bytedance

Implement stack variants and upward path sum

Last updated: Mar 29, 2026

Quick Overview

This question set evaluates data structure design and algorithmic reasoning—specifically stack variants (MinStack/MaxStack), online median maintenance for data streams, and upward path-sum detection in binary trees—assessing competencies in invariants, constant-time operation design, streaming algorithms, and tree traversal-based sum reasoning.

  • hard
  • Bytedance
  • Coding & Algorithms
  • Data Scientist

Implement stack variants and upward path sum

Company: Bytedance

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Onsite

Answer the following coding questions. 1. **MinStack**: Design a stack that supports `push(x)`, `pop()`, `top()`, and `getMin()` such that each operation runs in **O(1)** time. 2. **MaxStack**: Design a stack that supports `push(x)`, `pop()`, `top()`, and `getMax()` such that each operation runs in **O(1)** time. 3. **Median of a data stream**: Design a data structure that processes a stream of numbers and supports: - `addNum(x)`: insert a new number - `findMedian()`: return the current median Aim for efficient online updates. 4. **Binary tree upward path sum**: Given the root of a binary tree and a target sum, determine whether there exists a path whose values sum to the target, where the path: - may start at **any node**, - moves **only upward** toward ancestors, - contains one or more nodes, - and cannot revisit nodes. Return `true` if such a path exists, otherwise `false`.

Quick Answer: This question set evaluates data structure design and algorithmic reasoning—specifically stack variants (MinStack/MaxStack), online median maintenance for data streams, and upward path-sum detection in binary trees—assessing competencies in invariants, constant-time operation design, streaming algorithms, and tree traversal-based sum reasoning.

Related Interview Questions

  • Reverse Nodes in K-Sized Groups - Bytedance
  • Solve Bracket Matching and Tree Width - Bytedance (hard)
  • Reverse Linked List Groups - Bytedance (medium)
  • Solve Stack and String Shift Problems - Bytedance (medium)
  • Find LCA With Parent Pointers - Bytedance (medium)
Bytedance logo
Bytedance
Jan 10, 2026, 12:00 AM
Data Scientist
Onsite
Coding & Algorithms
1
0

Answer the following coding questions.

  1. MinStack : Design a stack that supports push(x) , pop() , top() , and getMin() such that each operation runs in O(1) time.
  2. MaxStack : Design a stack that supports push(x) , pop() , top() , and getMax() such that each operation runs in O(1) time.
  3. Median of a data stream : Design a data structure that processes a stream of numbers and supports:
    • addNum(x) : insert a new number
    • findMedian() : return the current median Aim for efficient online updates.
  4. Binary tree upward path sum : Given the root of a binary tree and a target sum, determine whether there exists a path whose values sum to the target, where the path:
    • may start at any node ,
    • moves only upward toward ancestors,
    • contains one or more nodes,
    • and cannot revisit nodes.

Return true if such a path exists, otherwise false.

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Bytedance•More Data Scientist•Bytedance Data Scientist•Bytedance Coding & Algorithms•Data Scientist Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ 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
  • Compare Platforms
  • Discord Community

Support

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

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.