A logging library batches log lines before sending them. Line i takes sizes[i] bytes. A batch must be a run of neighboring lines whose total size is at most budget bytes.
Write longestBatch(sizes, budget) that returns the largest number of neighboring lines that fit in one batch. If no single line fits, return 0.
Input: sizes = [2,1,5,1,3,2], budget = 7 Output: 3
[1, 5, 1] totals 7, and no run of 4 lines fits.
Input: sizes = [9,8], budget = 5 Output: 0
Every line alone is bigger than the budget.
0 <= sizes.length <= 1000000 <= sizes[i] <= 10^40 <= budget <= 10^9Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #135 Longest Run Within a Byte Budget. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.