HomeBlog › TikTok Coding Interview Questions

TikTok / ByteDance Coding Interview Questions

Fast, LeetCode-hard, and usually OA-first. TikTok and ByteDance reward speed and pattern recognition. Five worked problems and the full loop.

TikTok (and parent company ByteDance) runs one of the more demanding coding loops in big tech: it frequently starts with a timed online assessment of two to three LeetCode-style problems, and the onsite skews toward medium-to-hard difficulty solved quickly. Speed and pattern recognition matter more here than at companies that give you a full 45 minutes to think.

This guide covers five representative TikTok/ByteDance problems with worked Python, the OA-first loop, and how to build the speed the format demands.

The full interview process

StageFormatNotes
Online assessment (OA)60-90 min, 2-3 problemsTimed, auto-graded; the first filter
Technical phone screen45-60 min1-2 medium/hard problems live
Onsite coding (2-3)45-60 min eachMedium-to-hard, solved at pace
System design (mid/senior)45 minFeed ranking, video storage, scale
Behavioral / manager45 minOwnership, speed, "why ByteDance"

Problem 1: Longest Substring Without Repeating Characters (sliding window)

Question: Given a string, find the length of the longest substring without repeating characters.

A sliding window with a last-seen map. Expand the right edge; when you hit a repeat inside the window, jump the left edge past the previous occurrence.

def lengthOfLongestSubstring(s):
    last = {}
    left = 0
    best = 0
    for right, ch in enumerate(s):
        if ch in last and last[ch] >= left:
            left = last[ch] + 1
        last[ch] = right
        best = max(best, right - left + 1)
    return best

Time O(n), space O(min(n, charset)). The subtle part is last[ch] >= left — only move left when the duplicate is inside the current window, not before it. This is a classic OA problem; solve it without hesitation.

Problem 2: Sliding Window Maximum (monotonic deque)

Question: Given an array and a window size k, return the maximum of each sliding window as it moves left to right.

A monotonic decreasing deque of indices. The front is always the current window's max; pop smaller elements from the back as you add new ones, and drop indices that fall out of the window.

from collections import deque
def maxSlidingWindow(nums, k):
    dq = deque()  # indices, values decreasing
    out = []
    for i, num in enumerate(nums):
        while dq and nums[dq[-1]] <= num:
            dq.pop()
        dq.append(i)
        if dq[0] == i - k:
            dq.popleft()
        if i >= k - 1:
            out.append(nums[dq[0]])
    return out

Time O(n) — each index is pushed and popped at most once — space O(k). The monotonic deque is exactly the kind of pattern ByteDance OAs test. If you reach for a heap, mention it's O(n log k) and the deque is strictly better.

Problem 3: Median of Two Sorted Arrays (binary search, hard)

Question: Given two sorted arrays, find the median of their combined elements in O(log(m+n)).

Binary search on the partition of the smaller array so that the left halves of both arrays together form the lower half of the merged array.

def findMedianSortedArrays(a, b):
    if len(a) > len(b): a, b = b, a
    m, n = len(a), len(b)
    lo, hi = 0, m
    while lo <= hi:
        i = (lo + hi) // 2
        j = (m + n + 1) // 2 - i
        aL = a[i-1] if i > 0 else float('-inf')
        aR = a[i]   if i < m else float('inf')
        bL = b[j-1] if j > 0 else float('-inf')
        bR = b[j]   if j < n else float('inf')
        if aL <= bR and bL <= aR:
            if (m + n) % 2:
                return max(aL, bL)
            return (max(aL, bL) + min(aR, bR)) / 2
        elif aL > bR:
            hi = i - 1
        else:
            lo = i + 1

Time O(log(min(m,n))), space O(1). This is a genuine hard problem and ByteDance does ask it. The trick is binary-searching the partition, not the values. Practice the infinity-sentinel boundaries until they're automatic.

Problem 4: Number of Islands (BFS/DFS)

Question: Count islands of connected '1' cells in a 2D grid.

Flood-fill each unvisited land cell and count the fills. A reliable medium that appears in OAs and onsites alike.

def numIslands(grid):
    rows, cols = len(grid), len(grid[0])
    count = 0
    def sink(r, c):
        if 0 <= r < rows and 0 <= c < cols and grid[r][c] == '1':
            grid[r][c] = '0'
            sink(r+1, c); sink(r-1, c); sink(r, c+1); sink(r, c-1)
    for r in range(rows):
        for c in range(cols):
            if grid[r][c] == '1':
                count += 1
                sink(r, c)
    return count

Time O(rows×cols), space O(rows×cols) worst case. For very large grids in an OA, prefer an explicit stack/queue over recursion to avoid hitting Python's recursion limit — a practical detail ByteDance's larger test cases can expose.

Patterns TikTok asks most

PatternFrequencyNote
Sliding window / two pointers~25% of loopsStrings and arrays, OA favorites
BFS / DFS on grids & graphs~20%Islands, matrix problems
Binary search (incl. hard)~15%Median, allocate, rotated arrays
Heap / monotonic stack-deque~15%Sliding window max, top-k
Dynamic programming~15%Sequences and grids
Greedy / intervals~10%Scheduling, jumps

Common pitfalls specific to TikTok

A 4-week prep plan for a TikTok / ByteDance loop

  1. Week 1: Sliding window, two pointers, and BFS/DFS — the OA core. Solve timed sets of 2-3 problems in 75 minutes to simulate the assessment.
  2. Week 2: Binary search and heap/monotonic-deque patterns, including at least three hards.
  3. Week 3: Speed work — mediums in under 20 minutes each — plus the system design cheat sheet.
  4. Week 4: Mixed mock loops and a live-coding rehearsal.

Keep pace under the timer with live AI support

CoPilot Interview surfaces structured solutions in about 4 seconds during real Zoom and Teams calls. Free for Windows and macOS, invisible on screen-share.

Download free

FAQ

Does TikTok start with an online assessment?

Frequently, yes. TikTok and ByteDance often begin with a timed online assessment of two to three LeetCode-style problems that auto-grades your submissions. It's a hard filter, so practice timed sets, not just untimed solving.

How hard are TikTok / ByteDance coding questions?

Medium-to-hard, and they do ask genuine hards like median of two sorted arrays. The bar is speed plus pattern recognition - you're expected to solve mediums quickly rather than thinking for the full window.

What patterns should I prioritize for ByteDance?

Sliding window and two pointers, BFS/DFS on grids, binary search (including hard variants), and monotonic deque/heap patterns like sliding window maximum. These dominate both the OA and the onsite.

Is the TikTok onsite different from the OA?

The onsite is live and slightly broader - it adds system design for mid/senior roles and a behavioral round - but the coding difficulty is similar. Both reward fast, clean solutions.

Can CoPilot Interview help with ByteDance prep?

Yes. It returns optimal solutions with Big-O in about four seconds, which is ideal for building the speed ByteDance's format demands. Follow TikTok's stated rules during the live interview.