PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Bytedance

Implement stacks, median, and tree path sum

Last updated: Mar 29, 2026

Quick Overview

This question evaluates skills in designing and implementing efficient data structures and online algorithms, covering stack variants with constant-time operations, median maintenance for data streams, and ancestor-path sum reasoning in binary trees.

  • hard
  • Bytedance
  • Coding & Algorithms
  • Data Scientist

Implement stacks, median, and tree path sum

Company: Bytedance

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Onsite

Implement or discuss the following coding tasks. 1. Design a MinStack data structure that supports push, pop, top, and getMin in O(1) time. 2. Design a MaxStack that supports push, pop, top, peekMax, and popMax. Aim for constant-time top and efficient maximum operations. 3. Given a stream of numbers, design a data structure that can return the current median after each insertion. If helpful, explain whether ideas from the MaxStack design can or cannot be adapted. 4. Given a binary tree with integer values and a target sum, determine whether there exists a path whose endpoints are a node and one of its ancestors, so the path moves only upward from child to parent, and the sum of the values on that path equals the target. A single node counts as a valid path. You may preprocess parent pointers if needed.

Quick Answer: This question evaluates skills in designing and implementing efficient data structures and online algorithms, covering stack variants with constant-time operations, median maintenance for data streams, and ancestor-path sum reasoning in binary trees.

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

Implement or discuss the following coding tasks.

  1. Design a MinStack data structure that supports push, pop, top, and getMin in O(1) time.
  2. Design a MaxStack that supports push, pop, top, peekMax, and popMax. Aim for constant-time top and efficient maximum operations.
  3. Given a stream of numbers, design a data structure that can return the current median after each insertion. If helpful, explain whether ideas from the MaxStack design can or cannot be adapted.
  4. Given a binary tree with integer values and a target sum, determine whether there exists a path whose endpoints are a node and one of its ancestors, so the path moves only upward from child to parent, and the sum of the values on that path equals the target. A single node counts as a valid path. You may preprocess parent pointers if needed.

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.