Interview questions
Find a company or topic. Read the sources, then practice.
Loading the question library…
Find a company or topic. Read the sources, then practice.
Loading the question library…
Showing 4,526–4,550
Two players alternately remove the leftmost or rightmost stone and score the sum of the remaining stones; compute the final score difference under optimal play…
General practice
Two players alternately remove a prefix of length >1, add its sum to their score, and replace it by a single stone until one remains…
General practice
Determine whether Alice wins a deterministic take-away game where players must remove exactly 10, then 9, then 8, ... stones on successive turns; compute how…
General practice
Given a printer that in each turn prints a contiguous run of the same character and can overwrite existing characters, compute the minimum number of…
General practice
Given a target m×n grid, determine whether you can produce it by printing each color at most once as a solid axis-aligned rectangle that may…
General practice
Given a stream of characters, after each queried character determine whether any non-empty suffix of the accumulated stream matches a word from a given list…
General practice
Check whether an integer n (4 ≤ n ≤ 10^5) is "strictly palindromic" — i.e., its representation in every base b from 2 to n−2…
General practice
Given a string s and integer k, delete up to k characters to minimize the length of its run-length encoding; the core challenge is choosing…
General practice
Compress a lowercase string using run-length encoding by repeatedly removing the longest prefix of a single repeated character of length at most 9 and appending…
General practice
Determine whether t is a rotation of s; if so, count the number of k-length sequences of nonzero suffix-rotations (moves that rotate s by l…
General practice
Given two equal-length strings s and t, determine whether s can be converted into t by repeatedly replacing all occurrences of one character in s…
General practice
Construct a string of length a+b containing exactly a 'a's and b 'b's that never contains "aaa" or "bbb" (no three identical letters in a…
General practice
Given an array of equal-length strings, determine whether any two strings differ by exactly one character (Hamming distance = 1). Aim for better than brute-force…
General practice
Count how many strobogrammatic numbers (numbers that read the same when rotated 180°) lie within a given numeric range [low, high] (often provided as strings)…
General practice
Given an undirected friendship graph and a threshold k, determine which friendships or users are "strong"—typically defined by having at least k mutual friends or…
General practice
Given a password string, compute the minimum number of insertions, deletions, or replacements needed to make it "strong" — length 6–20, containing at least one…
General practice
Check whether an attendance string has strictly fewer than two 'A' characters and contains no run of three or more consecutive 'L' characters. Return true…
General practice
Count the number of length-n strings over {A,P,L} with fewer than 2 'A's and no three consecutive 'L's, returning the result mod 1e9+7. The core…
General practice
For every student-subject pair (each student takes every subject), count how many rows in Examinations record that student attended that subject (duplicates count multiple…
General practice
Aggregate student data across hierarchical geographic levels (e.g., country/state/city/school), requiring joins and multi-level grouping or conditional aggregation to produce a…
General practice
Given Students and Departments tables, return the names of students whose department ID does not match any entry in Departments (i.e., students assigned to an…
General practice
Count the number of contiguous subarrays whose sum is divisible by k; this reduces to counting pairs of prefix sums with the same remainder modulo…
Companies: TikTok
Array · Hash Table · Prefix Sum
Find any contiguous subarray of length k such that every element > threshold / k, and return that k (or -1 if none exists). Equivalently…
General practice
Return the sum, over all non-empty contiguous subarrays of nums, of the square of the number of distinct values in each subarray. The core challenge…
General practice
Compute the sum over all nonempty subarrays of (number of distinct elements)^2 in an integer array, returning the result modulo 1e9+7. With n up to…
General practice