Partition Into K Subarrays With Sum at Least X
Updated
Problem statement
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) → booleanExamples
Example 1
nums = [3,1,4,2,2]k = 3x = 4return = trueOne valid partition is [3,1] | [4] | [2,2]. All three subarray sums equal 4.
Example 2
nums = [100,1,1]k = 2x = 50return = falseThe 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 = trueThe 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 Onsite Interview questions
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Maximum Subarray SumCapital One · PHONE SCREEN · ONSITE INTERVIEWCapital One interview questions
- Maximum Game Score with Fixed Forward JumpsStripe · OAStripe interview questions
- Best Improvement Period of at Least K IntervalsAmazon · PHONE SCREEN
- Minimum Variance Sum SplitAirbnb · PHONE SCREENAirbnb interview questions
- Largest All-One Square Area and CountNVIDIA · PHONE SCREENNVIDIA interview questions
- Maximum Apples from Two Disjoint Fixed-Length SegmentsMarshall Wace · OAMarshall Wace interview questions
- Maximum Non-Decreasing Array LengthVisa · OAVisa interview questions
- Maximize CollaborationTikTok · OATikTok interview questions
- Maximum Sum RectangleDeloitte · OADeloitte interview questions
- Subarray Sum Equals KServiceNow · ONSITE INTERVIEWServiceNow interview questions