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 3,326–3,350
Find the maximum sum of any contiguous subarray of length k whose elements are all distinct. This is solved by scanning with a sliding window…
General practice
Given a connected undirected graph with max degree 2 (so it is a path or cycle), assign the unique labels 1..n to nodes to maximize…
General practice
After each point update to an array, compute the maximum sum of a subsequence with no two adjacent elements (i.e., the maximum-weight independent set on…
General practice
Companies: Amazon
Array · Greedy · Heap (Priority Queue) · Sorting
Given pairs (nums1[j], nums2[j]) with weight nums1[j]+nums2[j], answer each query by finding the maximum weight among points whose both coordinates are >= given thresholds —…
General practice
Given an integer array, compute the maximum possible "sum score" produced by choosing a selection (typically a split, rotation, or contiguous subarray) whose elements…
General practice
Pick up to k elements from an n×m matrix to maximize their total value, with the extra constraint that you may take at most limits[i]…
General practice
Given nums and k, perform k operations each time choosing an element m, adding m to your score, and replacing it with m+1; return the…
General practice
Given a nonnegative integer, perform at most one swap of two digits to obtain the largest possible number. This is solved greedily by identifying the…
Companies: Apple
Greedy · Math
Given an array of candy prices, pick k distinct candies to maximize the minimum pairwise absolute difference (the "tastiness"). With n up to 1e5, the…
General practice
Given a set of pistons (with sizes/extension limits and positions), choose how far each can extend or where to place them so their occupied regions…
General practice
Choose which gardens to raise to at least target using at most newFlowers to maximize full * (#complete) + partial * (minimum flowers among incomplete…
General practice
Given an array of spell damages, pick a subset to maximize total damage under the rule that choosing any value v forbids using values v-2…
General practice
Given pairs (value[i], limit[i]), find an activation order that maximizes the sum of values where you can activate i only if the current number of…
General practice
Given an undirected graph, assign unique labels 1..n to nodes to maximize the sum over edges of the sums of their endpoint labels — equivalently…
General practice
Select a sequence of elements from rewardValues (starting with total x = 0) so that each chosen value is strictly greater than the current total…
General practice
Starting from x = 0, you may repeatedly choose any unpicked element whose value is strictly greater than the current sum and add it to…
General practice
Since subarrays can overlap and be repeated, the optimal pick is any subarray containing the global maximum and minimum, so the maximum total is simply…
General practice
Pick exactly k distinct non-empty subarrays (overlaps allowed) to maximize the sum of their ranges (max - min). The core challenge is to efficiently compute…
General practice
Companies: Google, Infosys
Array · Binary Search · Greedy · Math