PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/TikTok

Implement stack variants and path-sum check

Last updated: Mar 29, 2026

Quick Overview

This question evaluates data-structure design and algorithmic skills including constant-time stack variants (min/max stacks), online algorithms for streaming median computation, upward-only path-sum reasoning in trees, and the ability to state time/space trade-offs and handle edge cases.

  • medium
  • TikTok
  • Coding & Algorithms
  • Machine Learning Engineer

Implement stack variants and path-sum check

Company: TikTok

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

## Coding tasks Solve the following algorithmic problems. ### 1) MinStack Design a stack supporting: - `push(x)`, `pop()`, `top()` - `getMin()` returning the minimum element currently in the stack All operations should run in **O(1)** time. ### 2) MaxStack Design a stack supporting: - `push(x)`, `pop()`, `top()` - `peekMax()` returning the maximum element currently in the stack - `popMax()` removing and returning the maximum element (if multiple maxima exist, remove the one closest to the top) State expected time complexities and trade-offs. ### 3) Streaming median (data stream) Given a very large stream of integers, support inserting numbers and querying the **current median** at any time. ### 4) Tree path sum with upward-only path Given a binary tree with **positive integer** node values and an integer `target`, determine whether there exists a **single-direction path that starts at any node and only moves upward to parent nodes** such that the sum of the nodes on that path equals `target`. Return `true/false`. Include any reasonable constraints you assume (e.g., number of nodes, value ranges) and handle edge cases (single node, skewed tree, large target).

Quick Answer: This question evaluates data-structure design and algorithmic skills including constant-time stack variants (min/max stacks), online algorithms for streaming median computation, upward-only path-sum reasoning in trees, and the ability to state time/space trade-offs and handle edge cases.

Related Interview Questions

  • Parse a nested list from a string - TikTok (medium)
  • Implement stacks, streaming median, and upward path sum - TikTok (easy)
  • Maximize sum with no adjacent elements - TikTok (medium)
  • Find the longest palindromic substring - TikTok (easy)
  • Solve common string/DP/stack problems - TikTok (medium)
TikTok logo
TikTok
Feb 12, 2026, 12:00 AM
Machine Learning Engineer
Technical Screen
Coding & Algorithms
5
0

Coding tasks

Solve the following algorithmic problems.

1) MinStack

Design a stack supporting:

  • push(x) , pop() , top()
  • getMin() returning the minimum element currently in the stack

All operations should run in O(1) time.

2) MaxStack

Design a stack supporting:

  • push(x) , pop() , top()
  • peekMax() returning the maximum element currently in the stack
  • popMax() removing and returning the maximum element (if multiple maxima exist, remove the one closest to the top)

State expected time complexities and trade-offs.

3) Streaming median (data stream)

Given a very large stream of integers, support inserting numbers and querying the current median at any time.

4) Tree path sum with upward-only path

Given a binary tree with positive integer node values and an integer target, determine whether there exists a single-direction path that starts at any node and only moves upward to parent nodes such that the sum of the nodes on that path equals target.

Return true/false.

Include any reasonable constraints you assume (e.g., number of nodes, value ranges) and handle edge cases (single node, skewed tree, large target).

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More TikTok•More Machine Learning Engineer•TikTok Machine Learning Engineer•TikTok Coding & Algorithms•Machine Learning Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,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.