← 返回 bytedance 的题目列表Kth Smallest Subarray Sum
类型:online_judge
Given an integer array nums and an integer k. Your task is to find the k-th smallest sum of subarrays in nums. A subarray is continuous, and the length of arrays can range from 0 to the length of nums. Write a function findKthSmallestSubarraySum(nums, k) to solve. Details for test cases:
Example 1:
Input: nums = [2, 1, 3, 4], k = 3
Output: 3 Explanation: The ordered sums of subarrays are [1, 2, 3, 3, 4, 6, 7, 9], and the third smallest is 3.
Example 2:
Input: nums = [1, 3, 5], k = 1
Output: 1
Note that the length of array nums is in the range of [1, 1000], and each element is in the range of [1, 1000].
Example
Input
2 1 3 4
3