FastPrepCombine the Two Smallest Until All Reach k
Problems/Combine the Two Smallest Until All Reach k

Combine the Two Smallest Until All Reach k

Adobe logoAdobe● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: This problem counts the steps of a process that keeps replacing the two smallest values x <= y of a list by 2x + y until every value is at least k, and returns -1 if a single value below k is left. An Adobe SDE-4 report gives, as the second question of its opening data-structures-and-algorithms round, only a link to a public problem and says the asked one was similar to it; the actual variation is not described.

Our choices: the linked problem's combine rule, -1 when one value remains below k (the linked problem promises an answer always exists), 1 to 5000 values, values and k up to 10^9, and new examples.

The judged task matches the report at about 60%.

You have a list of positive integers nums and a threshold k. One combine step removes the two smallest values x <= y from the list and adds the single value 2 * x + y.

Keep combining while the smallest value in the list is below k. Return how many steps you made. If the smallest value is still below k when only one value is left, return -1.

Note that new values can be larger than a 32-bit integer can hold.

Function

minCombineOps(nums: int[], k: int) → int

Examples

Example 1

nums = [7,1,12,3]k = 9return = 2

Combine 1 and 3 into 1 x 2 + 3 = 5: [7, 12, 5]. Combine 5 and 7 into 5 x 2 + 7 = 17: [12, 17]. Every value is now at least 9, after 2 operations.

Example 2

nums = [5,6]k = 5return = 0

Both values are already at least 5, so no operation is needed: 0.

Example 3

nums = [1,2,1]k = 20return = -1

Combine 1 and 1 into 3: [2, 3]. Combine 2 and 3 into 7: [7]. Only one value is left and it is below 20, so it is impossible: -1.

Constraints

  • 1 <= nums.length <= 5000
  • 1 <= nums[i] <= 10^9
  • 1 <= k <= 10^9

More Adobe problems

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
All Adobe interview questionsSee Adobe hiring insights
Saved
public int minCombineOps(int[] nums, int k) {
    // Write your code here.
}
Checking account…