There is a magical forest with N trees, each tree i (0 <= i < n) has ai fruits. You have a basket which has a capacity of K fruits (at most K). Once you enter the forest you are teleported to a random tree, say i. Choose a number L such that you have to collect all the fruits from that random index i to i + L - 1 (It is however a guarantee that you will land on a tree such that i < N - L). Maxmum value of L.
Input:
The first line of input is the number of trees and the value of K. The second line consists of N space-separated values denoting the number of fruits on each tree.
Output:
The maximum value of L
Examples
01 · Example 1
fruits = [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 maximumValueOfL(int[] fruits, int k) {
// write your code here
}
fruits[3, 1, 2, 4]
k8
expected3
sign in to submit