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 26–41
Given a total amount and number of children, allocate all money so each child gets at least $1 and nobody gets $4, and return the…
Companies: MongoDB
Greedy · Math
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
Companies: Atlassian
Binary Search · Greedy
Choose k workers and pay each proportional to quality while meeting their minimum wages; the group's cost equals (sum of selected qualities) * max(wage[i]/quality[i]) among…
Companies: Apple
Array · Greedy · Heap (Priority Queue) · Sorting
Given a target distance, initial fuel, and stations at positions with fuel amounts, determine the minimum number of refueling stops needed to reach the target…
Companies: D. E. Shaw, Uber, Waymo
Array · Dynamic Programming · Greedy · Heap (Priority Queue)
Given an array of positive integers where an operation halves any chosen element, find the minimum number of operations to reduce the total sum by…
Companies: Nutanix
Array · Greedy · Heap (Priority Queue)
Given n, you may add or subtract any power of two per operation; find the minimum number of such operations to reach 0. The core…
Companies: Salesforce, Uber
Bit Manipulation · Dynamic Programming · Greedy
Given an integer array where you may replace any element with two positive integers summing to it, find the minimum number of such split operations…
Companies: Salesforce
Array · Greedy · Math
Given two arrays and up to k1 and k2 unit +/-1 edits, minimize the sum of (nums1[i]-nums2[i])^2 by optimally allocating k = k1+k2 operations to…
Companies: Google
Array · Binary Search · Greedy · Heap (Priority Queue)
Partition the array into k contiguous nonempty subarrays where each bag's cost is the sum of its endpoint weights, so the total score equals weights[0]+weights[n-1]…
Companies: Salesforce
Array · Greedy · Heap (Priority Queue) · Sorting
Remove duplicate letters from s so each character appears exactly once and the resulting string is the smallest possible in lexicographic order. This is solved…
Companies: TikTok
Greedy · Monotonic Stack · Stack · String
Given an array of pile sizes and k operations each removing floor(pile/2) stones from a chosen pile (possibly the same pile multiple times), minimize the…
Companies: Salesforce
Array · Greedy · Heap (Priority Queue)
Given an array of positive integers (bag counts), remove beans (only deletions allowed) so that every non-empty bag has the same count, minimizing total beans…
Companies: D. E. Shaw
Array · Enumeration · Greedy · Prefix Sum
Given inventories where each sale of a color yields value equal to its current count and reduces that count by one, choose which balls to…
Companies: Goldman Sachs
Array · Binary Search · Greedy · Heap (Priority Queue)
Given a string s and an empty buffer t that acts like a stack (you can push s's first char onto t or pop t's…
Companies: Bloomberg, Expedia, Rippling
Greedy · Hash Table · Stack · String
Count the number of triplets (i, j, k) from nums that can form triangle side lengths — i.e., three values a ≤ b ≤ c…
Companies: Bloomberg
Array · Binary Search · Greedy · Sorting