PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Bytedance

Implement stack and tree algorithms

Last updated: Apr 2, 2026

Quick Overview

This question evaluates proficiency with stack and tree data structures, algorithm design for constant-time operations, and online/streaming median maintenance, and is commonly asked to assess a candidate's ability to augment data structures, manage time/space trade-offs, and reason about ancestor-chain path sums.

  • hard
  • Bytedance
  • Coding & Algorithms
  • Data Scientist

Implement stack and tree algorithms

Company: Bytedance

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Onsite

Solve the following algorithm problems: 1. Design a `MinStack` data structure that supports `push(x)`, `pop()`, `top()`, and `getMin()` in `O(1)` time. 2. Design a `MaxStack` data structure. Support the standard operations `push(x)`, `pop()`, `top()`, `peekMax()`, and `popMax()`. 3. Given a stream of numbers arriving one by one, compute the median in real time after each insertion. Explain the data structure you would use, and discuss whether ideas from the `MaxStack` design can be adapted to support this functionality efficiently. 4. Given a binary tree with integer node values and an integer `targetSum`, determine whether there exists a path whose nodes sum to `targetSum`, where the path may start at any node and may move only upward through parent links. In other words, every valid path must lie on a single ancestor chain, but it does not need to start at the root.

Quick Answer: This question evaluates proficiency with stack and tree data structures, algorithm design for constant-time operations, and online/streaming median maintenance, and is commonly asked to assess a candidate's ability to augment data structures, manage time/space trade-offs, and reason about ancestor-chain path sums.

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 4, 2026, 12:00 AM
Data Scientist
Onsite
Coding & Algorithms
5
0

Solve the following algorithm problems:

  1. Design a MinStack data structure that supports push(x) , pop() , top() , and getMin() in O(1) time.
  2. Design a MaxStack data structure. Support the standard operations push(x) , pop() , top() , peekMax() , and popMax() .
  3. Given a stream of numbers arriving one by one, compute the median in real time after each insertion. Explain the data structure you would use, and discuss whether ideas from the MaxStack design can be adapted to support this functionality efficiently.
  4. Given a binary tree with integer node values and an integer targetSum , determine whether there exists a path whose nodes sum to targetSum , where the path may start at any node and may move only upward through parent links. In other words, every valid path must lie on a single ancestor chain, but it does not need to start at the root.

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.