Problem · Array

Maximum Value of L (For off-campus 2025 batch hiring :)

EasyUberNEW GRADOA
See Uber hiring insights

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
drafts saved locally
public int maximumValueOfL(int[] fruits, int k) {
  // write your code here
}
fruits[3, 1, 2, 4]
k8
expected3
sign in to submit