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,601–4,625
Find the sum of the n smallest positive integers that are palindromic both in base-10 and in base-k. Efficient solutions generate decimal palindromes in increasing…
General practice
Enumerate all numeric values from s's substrings (ignoring leading zeros), deduplicate and test each for primality. Return the sum of the three largest unique primes…
General practice
Return the sum of values of all leaf nodes in a binary tree that are left children of their parents (i.e., nodes with no children…
General practice
Given an n×n zero matrix and queries that set entire rows or columns (overwriting previous values), compute the final matrix sum. Because later updates override…
Companies: Salesforce
Array · Hash Table
Find an integer cap such that replacing every element greater than the cap with the cap makes the array's sum as close as possible to…
General practice
Traverse the binary tree and return the sum of node values whose grandparent exists and is even-valued. This requires a tree traversal (DFS/BFS) while checking…
General practice
Check whether a non-negative integer num can be written as x + reverse(x) for some non-negative integer x (the reverse may include leading zeros). With…
General practice
Find the minimum number of positive integers (repetition allowed) whose units digit is k that sum to num, or return -1 if impossible. The problem…
General practice
Companies: Amazon, Google, Meesho
Array · Counting · Depth-First Search · Hash Table
For each word, compute the sum of counts of how many words in the array share each of its non-empty prefixes. The core challenge is…
General practice
Given an m×n grid with certain "source" cells, compute each cell's remoteness (minimum distance to the nearest source) and return the sum of those distances…
General practice
Given a binary tree with node values 0 or 1, interpret each root-to-leaf path as a binary number (root is the most significant bit) and…
General practice
Given a string s, compute the sum of lengths of the longest common prefixes between s and every suffix s[i:], i.e., sum LCP(s, s[i:]) for…
General practice
Companies: Amazon, Bloomberg
Array · Enumeration · Math · Sorting
Given an array, answer queries (and possibly point updates) that ask for the sum of elements at indices forming an arithmetic progression (a start index…
General practice
Determine whether a non-negative integer c can be expressed as a^2 + b^2 for integers a and b. With c up to 2^31−1, the typical…
General practice
Given a 1-indexed integer array nums of length n, compute the sum of squares of all elements at indices i that divide n (i.e., n…
Companies: Bloomberg
Array · Enumeration
Compute the sum of the minimum element of every contiguous subarray of arr, returned modulo 10^9+7. Because n can be up to 3·10^4, the intended…
General practice
Compute the sum of (maximum - minimum) over all contiguous subarrays of a given integer array. The challenge is to do this faster than brute…
General practice
Compute the sum of (max - min) over all non-empty subsequences modulo 1e9+7; the core idea is to sort the array and use combinatorics: each…
General practice
Return the sum of elements nums[i] for all indices i whose binary representation contains exactly k set bits (i.e., popcount(i) == k). Constraints are small…
General practice
For each index i in nums, sum the subarray from start = max(0, i − nums[i]) to i and return the total of all these…
General practice
Given an array and a weight rule, compute the sum of each subarray's weighted mode (the most frequent element in the range, with ties resolved…
General practice
Given a sorted, unique integer array, compress consecutive runs of numbers into the minimal list of inclusive ranges that exactly cover all elements. Output each…
General practice