FastPrepPartition Into K Subarrays With Sum at Least X
Problems/Partition Into K Subarrays With Sum at Least X

Partition Into K Subarrays With Sum at Least X

Google logoGoogle● MediumNEW GRADONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: An early-career Google virtual-onsite report asks whether a positive-integer list can be split into k ordered contiguous sublists whose minimum sum is at least x, then explicitly asks how negative values change the solution. This practice version judges the signed-integer follow-up and supplies the callable interface and bounds; the core task matches the report at about 92%.

You are given an integer array nums and integers k and x.

Can you split the entire array into exactly k nonempty consecutive parts, keeping the original order, so that each part has a sum of at least x?

Return true if such a partition exists. Otherwise, return false.

Implement canPartitionWithMinimumSum(nums, k, x).

Function

canPartitionWithMinimumSum(nums: int[], k: int, x: int) → boolean

Examples

Example 1

nums = [3,1,4,2,2]k = 3x = 4return = true

One valid partition is [3,1] | [4] | [2,2]. All three subarray sums equal 4.

Example 2

nums = [100,1,1]k = 2x = 50return = false

The only cut positions produce sums 100 and 2, or 101 and 1. In both cases, one subarray sum is below 50.

Example 3

nums = [10,-5,5]k = 2x = 5return = true

The partition [10,-5] | [5] has subarray sums 5 and 5. Cutting immediately after 10 would fail, which is why a positive-only greedy rule does not handle negative values.

Constraints

  • 1 <= nums.length <= 2000.
  • 1 <= k <= nums.length.
  • -10^9 <= nums[i] <= 10^9.
  • 1 <= x <= 10^9.
  • Subarray sums may exceed 32-bit integer range.

More Google problems

  • Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
  • Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
  • 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public boolean canPartitionWithMinimumSum(int[] nums, int k, int x) {
      // write your code here
    }
}
Checking account…