You are given an array of n magical fruits. The power of the fruit is given in an array of length n. You are also given an integer k. Your task is to find the maximum length L such that every subarray of length L has the sum of powers strictly less than k.
Input Format
The first line contains two integers n and k — the number of fruits and the maximum allowed power sum. The second line contains n integers — the array a, where a[i] is the power of the i-th fruit.
Output Format
Print a single integer — the maximum value of L.
Constraints
1 ≤ n ≤ 2 * 10^51 ≤ a[i] ≤ 10^91 ≤ k ≤ 10^18
Examples
01 · Example 1
a = [3, 1, 2, 4] k = 8 return = 3
🦐
More Uber problems
- Total Palindrome Substring CostOA · Seen Jun 2026
- Earliest Time All Users Are ConnectedPHONE SCREEN · Seen May 2026
- Tournament Rounds by RankPHONE SCREEN · Seen May 2026
- Farthest Seat AssignmentONSITE INTERVIEW · Seen May 2026
- Convex Function MinimizationPHONE SCREEN · Seen May 2026
- Maximal Square AreaONSITE INTERVIEW · Seen May 2026
- First Unique IP Hitting the ServerPHONE SCREEN · Seen May 2026
- Jump Game with Prime-Step RuleOA · Seen May 2026
public int findMaximumLength(int[] a, int k) {
// write your code here
}
a[3, 1, 2, 4]
k8
expected3
sign in to submit