PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/TikTok

Implement stacks, streaming median, and upward path sum

Last updated: Jun 16, 2026

Quick Overview

This multi-part question evaluates proficiency in data structure design (augmented stacks for min/max, data structures for streaming medians), order-statistics and real-time aggregation, and constrained binary-tree traversal for upward-only paths, while requiring clear time/space complexity analysis and edge-case reasoning; such prompts are commonly asked to assess efficient state management, invariant maintenance, and algorithmic trade-off reasoning in the Coding & Algorithms domain. The level of abstraction spans practical implementation and conceptual understanding, emphasizing implementation-level details and complexity analysis for data-structure augmentation, streaming algorithms, and constrained tree traversal.

  • easy
  • TikTok
  • Coding & Algorithms
  • Data Scientist

Implement stacks, streaming median, and upward path sum

Company: TikTok

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Onsite

Round 1: Discuss how to deploy multimodal models under compute and GPU memory constraints. Follow-up: Given existing captions and embeddings, how to speed up video retrieval. What is overfitting and how to mitigate it. Coding: Implement MinStack that returns the minimum value in O(1) time. Round 2: Discuss methods to mitigate overfitting in deep learning and the principles behind Dropout. Compare different normalization methods and how to handle them during inference. Discuss the application of reinforcement learning in LLM post-training (RLHF). Coding: Implement MaxStack. Follow-up: How to compute the median in real-time from a data stream, and how to modify MaxStack to achieve this. Round 3: Explain Dropout again and why it maintains distribution consistency. Coding: Given a binary tree, determine whether there exists a path starting from any node, moving only upward, whose sum equals a target value.

Quick Answer: This multi-part question evaluates proficiency in data structure design (augmented stacks for min/max, data structures for streaming medians), order-statistics and real-time aggregation, and constrained binary-tree traversal for upward-only paths, while requiring clear time/space complexity analysis and edge-case reasoning; such prompts are commonly asked to assess efficient state management, invariant maintenance, and algorithmic trade-off reasoning in the Coding & Algorithms domain. The level of abstraction spans practical implementation and conceptual understanding, emphasizing implementation-level details and complexity analysis for data-structure augmentation, streaming algorithms, and constrained tree traversal.

Related Interview Questions

  • Parse a nested list from a string - TikTok (medium)
  • Solve common string/DP/stack problems - TikTok (medium)
  • Implement stack variants and path-sum check - TikTok (medium)
  • Maximize sum with no adjacent elements - TikTok (medium)
  • Find the longest palindromic substring - TikTok (easy)
TikTok logo
TikTok
Feb 17, 2026, 10:50 PM
Data Scientist
Onsite
Coding & Algorithms
8
0

Complete the following coding problems. State the time/space complexity and key edge cases for each.

1) MinStack

Design a stack that supports:

  • push(x)
  • pop()
  • top()
  • getMin() : returns the current minimum value in the stack

getMin() must run in O(1) time (all other operations should also be amortized O(1)).

2) MaxStack

Design a stack that supports:

  • push(x)
  • pop()
  • top()
  • peekMax() : returns the current maximum value in the stack
  • popMax() : removes and returns the current maximum value (if there are duplicates, pop the one closest to the top of the stack)

Describe your chosen data structure and its complexity.

3) Streaming Median from a Data Stream

Design a data structure that receives numbers from a continuous stream and supports:

  • addNum(x)
  • findMedian() : returns the median of all elements seen so far

Target efficiency: insertion O(log n), query O(1).

4) How to Modify MaxStack to Support Real-Time Median

Building on your MaxStack implementation, discuss how to adapt or extend the data structure so that it supports stack-like operations while also efficiently supporting findMedian(). Describe the additional structures needed, complexity, and how to maintain consistency.

5) Binary Tree: Upward-Only Path Sum

Given a binary tree and an integer targetSum, determine whether there exists a path such that:

  • The path can start from any node ;
  • Each step can only move from the current node to its parent (i.e., the path direction is strictly upward);
  • The sum of node values along the path equals targetSum .

Output: whether such a path exists (true/false).

Note: If the node structure does not include a parent pointer, assume the input provides root, and you need to handle the "upward" constraint during traversal.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More TikTok•More Data Scientist•TikTok Data Scientist•TikTok Coding & Algorithms•Data Scientist Coding & Algorithms
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
  • Compare Platforms
  • Discord Community

Support

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

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.