TikTok Coding & Algorithms Interview Questions
Master your tech interview with our curated database of real questions from top companies.
Maximize Distinct Purchases Within Budget Constraints
Scenario Given a customer budget and a list of product prices, determine the maximum number of distinct products the customer can afford. Question Des...
Compute Averages of Unique Numbers in Dictionary Lists
Scenario Python tech screen: given a dictionary mapping keys to numeric lists, e.g., {'a':[1,2,1],'b':[1,2,3]}, compute the average of each list after...
Optimize Job Routing in Parallel Machine Scheduling
Scenario In the Production Factory game, jobs with varying processing times arrive and must be routed through two parallel machines to minimize total ...
Count subarrays summing to target
Question LeetCode 560. Subarray Sum Equals K – Given an integer array nums and an integer k, return the total number of continuous subarrays whose sum...
Flatten object & Promise.all
Question Given a nested JavaScript object, write a function to flatten it so that nested keys are converted to a single-level path (e.g., {a:{b:1}} ->...
Optimize Station Sequence for Maximum Car Output in Simulation
Scenario The Car-Building mini-game lets you sequence chassis, engine, and paint stations with limited buffers. Question Describe a strategy to maximi...
Count deletions making array fair
Question LeetCode 1664. Ways to Make a Fair Array – Given an integer array nums, count the indices whose removal results in the sum of elements at eve...
Solve intervals and distinct islands
Question LeetCode 56. Merge Intervals LeetCode 694. Number of Distinct Islands https://leetcode.com/problems/merge-intervals/description/ https://leet...
Analyze DFS, BFS, and A* trade-offs
Given a weighted graph with nodes {S,A,B,C,D,G} and edges: S–A(2), S–B(5), A–C(2), B–C(1), C–D(2), D–G(1), B–G(20). Heuristic for A: h(A)=4, h(B)=3, h...
Implement K-means and run two iterations
Given points P={(0,0),(0,2),(2,0),(2,2),(8,8),(8,10),(10,8),(10,10)} and k=2, (1) initialize centroids with k-means++ using seed=42 and Euclidean dist...
Compute pipeline order from dependencies
You are given a set of pipelines and a list of directed dependency pairs (A, B) meaning pipeline A depends on pipeline B and therefore B must run befo...
Compute rooms and verify tree completeness
1) Given a list of closed-open time intervals [start, end) representing meetings on a single calendar, compute the minimum number of rooms required so...
Implement binary tree in-order traversal
Given the root of a binary tree, return the in-order ordering of its node values. Implement both a recursive solution and an iterative solution using ...
Compute longest increasing subsequence
Given an integer array nums, compute the length of a longest strictly increasing subsequence and also output one valid subsequence. Aim for an O(n log...
Segment a message with width-constrained suffixes
Given a message string s and an integer width W, split s into consecutive segments and append a suffix "i/n" to each segment indicating its 1-indexed ...
Implement a match-3 eliminator
Implement a 2D match-3 eliminator: Given an m×n grid of integers, repeatedly remove any cells that belong to a horizontal or vertical run of length ≥ ...
Determine frog reachability across stones
You are given a sorted array of distinct integers stones representing stone positions in a river, where stones[0] = 0. A frog starts on stone 0; its f...
Find top-k rated nodes via traversal
You are given a finite graph (directed or undirected) with n nodes and m edges. Each node u has an integer rating r[u]. Given a starting node s and an...
Find >n/3 elements in sorted array
Given a sorted array of integers nums of length n, return all values that occur more than floor(n/ 3) times. Design an algorithm that runs in O(log n)...
Find >n/3 elements in sorted array
Given a sorted (non-decreasing) integer array A of length n, return all distinct values that occur strictly more than n/3 times. Design an algorithm t...