DevsUnite

ByteDance Interview Questions

33 real coding interview questions recently asked at ByteDance, spanning Algorithms, with a real difficulty tag and a direct LeetCode link for every question.

By DevsUnite · 33 Problems

Total Problems: 33Difficulty Levels:EasyMediumHard

Loading your progress…0/33
Implement Queue using Stacks
LeetCodeEasy

A design problem: implement a FIFO queue using only two LIFO stacks. It tests whether a candidate understands the classic technique of using one stack for pushes and lazily transferring elements to a second stack (reversing their order) only when the second stack is empty and a pop/peek is needed. It's a compact, well-known signal for whether a candidate can reason about amortized time complexity rather than just correctness.

Daily Temperatures
LeetCodeMedium

Given a list of daily temperatures, find for each day how many days you'd have to wait until a warmer temperature. It's a canonical monotonic-stack problem: maintaining a decreasing stack of indices and resolving them, computing the wait, whenever a warmer day is encountered. It's a strong, quick check on whether a candidate recognizes the monotonic-stack pattern rather than defaulting to a brute-force O(n^2) scan.

Merge k Sorted Lists
LeetCodeHard

Merging k sorted linked lists efficiently requires either a min-heap holding the current head of each list (repeatedly popping the smallest and pushing its successor) or a divide-and-conquer pairwise merge, both achieving O(N log k). It tests whether a candidate can extend the two-list merge pattern to k lists and reason about the resulting complexity rather than defaulting to an O(Nk) linear scan across lists. Correct pointer management across multiple linked lists under time pressure is the practical difficulty.

LRU Cache
LeetCodeMedium

A design problem requiring O(1) get and put operations with least-recently-used eviction, implemented by combining a hash map (for O(1) lookup) with a doubly linked list (for O(1) reordering and eviction from either end). This exact structure underlies real inference key-value caches — it's reportedly one of the most frequently asked design questions at companies building LLM inference systems, since eviction policy for a bounded cache maps directly onto managing GPU memory for attention KV caches. It's a strong test of whether a candidate can compose two data structures to get O(1) across every required operation, not just some of them.

Max Consecutive Ones III
LeetCodeMedium

Given a binary array and an integer k, find the length of the longest subarray of 1s obtainable after flipping at most k zeros. It's a classic variable-size sliding-window problem: expanding the window while tracking the count of zeros inside it, and shrinking from the left once that count exceeds k. It's a reliable signal for sliding-window fluency, a pattern that recurs across many array and string problems in interviews.

Sliding Window Maximum
LeetCodeHard

This problem asks for the maximum value in every fixed-size window as it slides across an array, and the naive per-window scan is O(nk), so the real test is whether you can get to O(n) using a monotonic deque that stores candidate indices in decreasing order of value. You need to correctly pop from the back whenever a new element invalidates smaller values still in the deque, and pop from the front whenever the window's leftmost index expires. It's a strong signal for whether a candidate can reason about amortized complexity and maintain a non-obvious data-structure invariant under a moving constraint, rather than just knowing the deque trick by rote.

Number of Islands
LeetCodeMedium

A grid graph-traversal problem: count connected components of '1' cells using DFS, BFS, or Union-Find, being careful with boundary checks and marking visited cells so you don't recount. It's one of the most common entry points into grid-based graph problems and is often used as a warm-up before harder multi-source or Union-Find variants. The core signal is whether a candidate can translate a 2D grid into an implicit graph and correctly implement flood-fill without off-by-one or infinite-loop bugs.

Binary Tree Maximum Path Sum
LeetCodeHard

A hard tree problem: find the maximum sum of any path between any two nodes in a binary tree, where the path need not pass through the root. It tests whether a candidate can write a DFS that returns the best single-branch sum upward to a parent (for the recursive contract) while separately tracking a global maximum that considers both branches meeting at the current node. It's a well-known hard-tier tree-recursion problem precisely because those two concerns are easy to conflate.

Trapping Rain Water
LeetCodeHard

Given an elevation map, compute how much water it can trap after rain — the water trapped at each index equals the shorter of the tallest bars to its left and right, minus its own height. It's solvable with two pointers in O(1) extra space, with a monotonic stack, or with two precomputed max-prefix/max-suffix arrays, making it a great vehicle for comparing multiple valid techniques in one interview. Its breadth of companies asking it reflects that it's one of the most widely used checks of two-pointer/array reasoning in the entire interview circuit.

3Sum
LeetCodeMedium

Find all unique triplets in an array that sum to zero. The standard approach sorts the array, then for each element uses a two-pointer sweep over the remaining elements, carefully skipping duplicate values to avoid repeated triplets in the output. It extends the simpler two-pointer/two-sum pattern into a triplet setting and tests whether a candidate can handle the deduplication logic correctly, which is where most candidates lose points.

Longest Valid Parentheses
LeetCodeHard

A hard problem: find the length of the longest contiguous substring of well-formed parentheses. It tests whether a candidate can go beyond simple bracket-matching to either a stack-based approach that tracks indices for length computation, or an O(1)-space two-pass counting approach (left-to-right and right-to-left) or DP. It's a meaningfully harder variant of the classic Valid Parentheses problem and a good signal for whether a candidate can extend a familiar pattern to a substring-length variant.

N-Queens
LeetCodeHard

A hard, classic backtracking problem: place n queens on an n×n chessboard so that no two attack each other, and return all valid configurations. It tests whether a candidate can build a recursive search that places one queen per row, prunes branches early using column and diagonal conflict tracking, and backtracks cleanly. It's one of the most canonical constraint-satisfaction backtracking problems, making it a strong general signal for recursive search design.

Serialize and Deserialize Binary Tree
LeetCodeHard

A design problem: encode a binary tree into a string and reconstruct an identical tree from that string, typically via a preorder traversal with explicit null markers, or a BFS-based level encoding. The candidate must design a format that's unambiguous enough for deserialization to rebuild structure without extra information. Interview relevance frequently maps to data persistence — serializing structured data for storage or transmission and reliably reconstructing it — which is why it shows up across companies handling tree-like or hierarchical data on disk or over the wire.

Coin Change
LeetCodeMedium

A canonical unbounded-knapsack dynamic programming problem: given coin denominations and a target amount, find the minimum number of coins needed to make that amount (or determine it's impossible). The standard solution builds a bottom-up DP array where each amount's answer depends on smaller amounts reduced by each coin denomination. It's often used to gauge whether a candidate can correctly set up and reason about a 1D DP recurrence and its base cases, a foundational skill for many other DP problems.

Regular Expression Matching
LeetCodeHard

Implement regular expression matching supporting `.` (any single character) and `*` (zero or more of the preceding element) against a full string. The standard solution is a 2D dynamic program over (string index, pattern index), where the transition for `*` requires considering both 'match zero occurrences' and 'match one more occurrence' cases. It's widely regarded as one of the trickier string DP problems because the `*` transitions are easy to get subtly wrong, making it a good test of precise DP formulation under pressure.

Longest Increasing Path in a Matrix
LeetCodeHard

A hard problem: find the length of the longest strictly increasing path in a matrix, moving in four directions. It tests whether a candidate can combine DFS with memoization — treating each cell's longest path as a subproblem cached to avoid recomputation — effectively turning the matrix into a DAG (since values only increase along a path) that supports dynamic programming. It's a good signal for recognizing when grid traversal needs memoization to avoid exponential blowup.

Minimum Difference in Sums After Removal of Elements
LeetCodeHard

A hard problem: given an array of size 3n, remove exactly n elements so that among the remaining 2n, the sum of the first n minus the sum of the last n is minimized. It tests whether a candidate can maintain, for every possible split point, the minimum achievable sum of n elements from the prefix and the maximum achievable sum of n elements from the suffix — typically using a fixed-size max-heap for the running prefix minimum and a fixed-size min-heap for the running suffix maximum. It's a strong test of combining heaps with prefix/suffix aggregation, a less common but recurring hard-problem pattern.

Search in Rotated Sorted Array
LeetCodeMedium

A binary-search problem: find a target value's index in a rotated sorted array in O(log n) time. It tests whether a candidate can identify which half of the array around the midpoint is properly sorted at each step, then decide whether the target falls within that sorted half or the other one. Its wide reach across companies reflects how well it isolates genuine binary-search intuition from candidates who only know the textbook sorted-array version.

Kth Largest Element in an Array
LeetCodeMedium

This problem can be solved with a fixed-size min-heap of size k (keeping the k largest elements seen so far) for O(n log k), or with quickselect — a partition-based approach related to quicksort — for expected O(n). It's frequently used to gauge whether a candidate knows more than one approach and can reason about the time/space tradeoffs between a heap-based streaming solution and an in-place partitioning one. Handling duplicate values and off-by-one indexing during partition are common places candidates slip up.

Course Schedule II
LeetCodeMedium

A classic topological-sort problem: given courses and prerequisite pairs, return a valid ordering (or detect that no valid ordering exists due to a cycle). It tests whether a candidate can build an adjacency list, track in-degrees, and run Kahn's BFS algorithm (or DFS with visited/in-progress marking) to order and cycle-detect simultaneously. Its broad company reach reflects how often real systems need this exact shape of problem — resolving build or package dependency order, or task scheduling graphs — making it a reliable signal for graph traversal fluency.

Gas Station
LeetCodeMedium

Given circular gas stations with gas amounts and travel costs between them, determine the starting station, if any, from which a car can complete the full circuit. It's a classic greedy problem: if total gas is at least total cost a solution is guaranteed to exist, and a single linear pass tracking a running tank balance, resetting the candidate start whenever the balance goes negative, finds it in O(n). It's a good signal for recognizing a greedy invariant rather than reaching for a more expensive simulate-every-start approach.

The kth Factor of n
LeetCodeMedium

Given two integers n and k, return the kth smallest factor of n, or -1 if fewer than k factors exist. It's a straightforward problem testing basic divisibility checks and counting, typically solved by scanning from 1 to n and counting divisors, or the more efficient version scanning only up to sqrt(n) and collecting factor pairs. It's a lightweight, easy-to-medium problem often used as a warm-up before harder number-theory or search questions.

Zero Array Transformation I
LeetCodeMedium

Given an array and a list of range-decrement queries, determine whether it's possible to reduce every element to zero after processing all of the queries in order, where each query lets you decrement any subset of indices within its range by 1 (you choose which indices within the range, not which queries to apply — every query is processed). It tests whether a candidate recognizes the difference-array (or prefix-sum) technique for applying range updates in O(1) per query instead of O(range), then checks that each index's original value doesn't exceed the total number of queries covering it. It's a good signal for range-update-efficiency intuition, a recurring pattern in array problems involving repeated range operations.

Maximum Area Rectangle With Point Constraints I
LeetCodeMedium

Given a set of points on a plane, find the maximum-area axis-aligned rectangle whose four corners are all given points and which contains no other given point anywhere inside it or on its border — only the four corner points themselves may touch the rectangle's edges. It tests whether a candidate can combine hash-set lookups, to confirm all four corners exist, with a systematic check of whether any other point falls inside or on the edges of the candidate rectangle, iterating over pairs of x and y coordinates efficiently enough for the given constraints. It's a geometry-flavored problem that rewards careful boundary-versus-interior reasoning alongside standard pairing and enumeration techniques.

Maximize Amount After Two Days of Conversions
LeetCodeMedium

Given a starting currency and amount, and two separate days' worth of currency-conversion rates (each convertible in both directions), find the maximum amount of the initial currency obtainable after converting through day one's rates, holding, then converting back through day two's rates. It tests whether a candidate can model each day's rates as a graph and use DFS to propagate reachable amounts for every currency, then combine the two days' results — day one forward from the initial currency, day two effectively in reverse — to find the best round trip. It's a solid test of graph traversal with multiplicative, rather than additive, edge weights.

Count Unhappy Friends
LeetCodeMedium

Given a friend-pairing and each person's preference ranking of all other friends, count how many people are 'unhappy' — paired with someone while preferring another person who also prefers them over their own current partner. It tests whether a candidate can precompute preference rankings into a hash map for O(1) comparisons, then simulate the unhappiness condition for every person against everyone they rank higher than their current partner. It's a simulation-heavy problem that rewards careful precomputation over repeated brute-force list scanning.

Continuous Subarray Sum
LeetCodeMedium

Given an array and an integer k, determine whether the array has a contiguous subarray of size at least two whose sum is a multiple of k. It tests whether a candidate can use the prefix-sum-modulo trick — storing the first index at which each remainder (prefix sum mod k) occurs in a hash map, since two prefixes sharing the same remainder means the subarray between them sums to a multiple of k. It's a classic example of turning a divisibility condition into a hash-map lookup problem, a pattern that appears in several subarray-sum variants.

Number of Islands II
LeetCodeHard

This is an online version of the classic islands problem: land cells are added one at a time and you must report the island count after each addition, so recomputing a full BFS/DFS every step is too slow. The intended solution is a Union-Find (Disjoint Set Union) structure with path compression and union by rank, merging newly added land with its already-land neighbors. It's a strong signal for whether a candidate recognizes when a dynamic, incremental connectivity problem calls for DSU instead of repeated graph traversal.

K Inverse Pairs Array
LeetCodeHard

This problem asks how many permutations of 1..n contain exactly k inverse pairs, and it's a dense dynamic programming exercise rather than a graph or string problem. Naively, computing each dp[i][j] state means summing up to n prior terms, which balloons total runtime well past what n, k up to 1000 can tolerate; the real test is whether a candidate can spot the sliding-sum relationship between dp[i][j] and dp[i][j-1] (dp[i][j] = dp[i][j-1] + dp[i-1][j] - dp[i-1][j-i]) so each state resolves in O(1), bringing the total down to O(n*k). It's a good filter for comfort with less common DP-on-counting formulations under a modulo constraint.

Sliding Window Median
LeetCodeHard

This combines two well-known techniques — the sliding window pattern and the two-heap median-maintenance trick — into one harder problem, since elements must also be removable as the window slides past them. Because heaps don't support efficient arbitrary deletion, the standard solution uses lazy deletion (marking values as invalid and cleaning them up when they surface at a heap's top). It tests whether a candidate can adapt a known technique (median-of-stream via two heaps) to a scenario with removals, which trips up candidates who've only memorized the static version.

Basic Calculator II
LeetCodeMedium

A stack-and-string-parsing problem: evaluate an expression containing +, -, *, / (no parentheses) while respecting standard operator precedence. The typical approach scans left to right, pushing signed numbers onto a stack and immediately resolving * and / against the last pushed value, then summing the stack at the end. It's a solid check of careful state-machine parsing and edge-case handling (multi-digit numbers, whitespace, consecutive operators) under time pressure.

The Maze
LeetCodeMedium

A grid traversal variant where the "ball" doesn't move one cell at a time but rolls in a direction until it hits a wall, which changes what counts as a valid "move" in the search. Candidates typically solve it with BFS or DFS where each expansion step is itself a mini-simulation loop rather than a single-cell step. It's a useful signal for whether someone can adapt a standard graph-search template to a non-standard transition function instead of forcing the problem into the textbook shape.

Decode Ways II
LeetCodeHard

An extension of the classic "Decode Ways" DP where the string can also contain a wildcard '*' representing any digit 1-9, which multiplies the number of transition cases at each DP step. The core recurrence is still counting ways based on the last one or two characters, but correctly enumerating what each '*' can represent (alone or paired with a preceding digit) is where most bugs happen. It's a good test of DP correctness discipline and exhaustive case handling rather than DP concept knowledge alone.

Log in to save your progress, favorites, and notes to your account.

Frequently asked questions

What coding interview questions does ByteDance ask?

This page tracks 33 real, recently reported ByteDance coding interview questions, organized by topic: Algorithms.

How many ByteDance interview questions are on this list?

33 questions in total: 1 Easy, 18 Medium, and 14 Hard, each linked to its real LeetCode problem page.

Is it free to use?

Yes. Browsing every problem on this page is completely free, with no account required. Creating a free DevsUnite account lets you save your checked-off progress, star favorites, and add personal notes that sync across devices.

Do I need an account to track my progress?

You can read and solve every problem without logging in. An account is only required to mark a problem as done, star it, or add a note. Those actions save to your account instead of resetting on refresh.