FastPrepFastPrep
Problem Brief

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

NEW GRADOA

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

1Example 1

Input
fruits = [3, 1, 2, 4], k = 8
Output
3
Explanation
:)
public int maximumValueOfL(int[] fruits, int k) {
  // write your code here
}
Input

fruits

[3, 1, 2, 4]

k

8

Output

3

Sign in to submit your solution.