Tiktok Software Engineer Coding & Algorithms Interview Questions
Master your tech interview with our curated database of real questions from top companies.
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}} ->...
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...
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...
Design LRU cache with O(1) operations
Design and implement an in-memory cache that evicts the least recently used entry when capacity is reached. Support get(key) and put(key, value) in O(...
Compute waits and find distance-k node pairs
Part 1 — Array next-higher wait: Given an integer array A where A[i] is the measurement for day i (0-indexed), return an array W of the same length su...
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 ...
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)...
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 ≥ ...
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...
Solve grid min path and sqrt by binary search
1) Given an m x n matrix of non-negative integers, find a path from the top-left to the bottom-right that minimizes the sum of cell values. You may on...
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...
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...
Count islands on a torus grid
You are given an m x n binary grid representing water ( 0) and land ( 1) laid out on a torus: the top edge is adjacent to the bottom edge and the left...
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 ...
Find substring where all chars appear at least k
You are given a string s and an integer k (1 ≤ k ≤ |s|). Return the length of the longest substring in which every distinct character occurs at least ...
Solve four algorithm design tasks
Solve the following four algorithmic tasks: 1) Implement wildcard pattern matcher: Given a text s and a pattern p where '?' matches any single charact...
Solve three algorithm tasks
Solve the following algorithm tasks and explain your approach, time complexity, and space complexity for each: 1) Fully justify text: Given an array o...
Solve array and tree algorithm challenges
Solve the following three algorithmic tasks: 1) Unique triplet sum: Given an integer array nums and an integer target (default 0), return all unique t...
Solve Topological Sort and Anagram Indices
1) Given a directed graph (n vertices, m edges), return a topological ordering if one exists. If the graph contains a cycle, detect it and explain how...