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,126–4,150
Given an n×n integer matrix, return the largest prime number that appears on either the main diagonal or the anti-diagonal (or 0 if none). Note…
General practice
Count how many integers in [left, right] have a prime number of 1-bits in their binary representation. Compute each number's popcount and check it against…
General practice
Find all prime pairs (x, y) with 1 ≤ x ≤ y ≤ n and x + y = n, returning them sorted by x…
General practice
Find the smallest integer >= n that is both prime and a decimal palindrome. The challenge is to do this efficiently for n up to…
General practice
Determine whether you can make nums strictly increasing by, for each index at most once, subtracting any prime smaller than nums[i] (or leaving it unchanged)…
General practice
Given a binary tree, produce an m x n string matrix (m = height+1, n = 2^(height+1)-1) that visually represents the tree by placing the…
General practice
Coordinate two threads—one calling foo() and the other calling bar()—so their prints strictly alternate to produce "foobar" repeated n times. The challenge is enforcing correct…
General practice
Ensure three methods invoked by separate threads execute in the fixed order first → second → third despite arbitrary scheduling, by using synchronization primitives so…
General practice
Given a sentence of space-separated words, return the vertical reading by treating each word as a row and collecting characters column-by-column (i.e., the i-th string…
General practice
Coordinate three threads—zero(), even(), and odd()—to print the interleaved sequence "0 1 0 2 0 3 ..." up to n (total length 2n), ensuring zeros…
General practice
Given an 8-cell binary row updated daily where each interior cell becomes 1 iff its two neighbors are equal (edge cells become 0), return the…
General practice
Given counts of k colored balls summing to 2n, compute the probability that after a uniform random shuffle and splitting the first n balls into…
General practice
Process a sequence of friend requests using a disjoint-set to maintain friend groups, accepting a request only if merging the two components would not put…
General practice
Simulate processing s left-to-right to build a result string where letters append, '*' deletes the last character if present, '#' duplicates the entire current result…
General practice
Given s of letters and special ops where a letter appends, '*' deletes the last char, '#' duplicates the entire current string, and '%' reverses…
General practice
Simulate assigning tasks that arrive each second to servers, always choosing the available server with the smallest weight (breaking ties by index) and, if none…
General practice
Design a data structure that supports appending integers (including zeros) to a stream and returning the product of the last k numbers; the core challenge…
General practice
Given two run-length encoded arrays (lists of [value, frequency] pairs) representing two sequences, compute the element-wise product sequence and return its run-length…
General practice
For each product, determine its price on 2019-08-16 by taking the most recent price change on or before that date and returning that price (or…
General practice
Join the Sales and Product tables on product_id and return, for each sale_id, the corresponding product_name along with the sale year and unit price. The…
General practice
Write an SQL query that joins product and sales data to compute each product's total sales using GROUP BY, then return the product records that…
General practice
For each product_id, determine the earliest year it was sold and return all sales rows from that first year with columns product_id, first_year, quantity, and…
General practice