A file uploader sends files in batches. Each batch can hold at most two files, and the total size of a batch can't exceed limit megabytes. Every single file is at most limit.
Write fewestBatches(sizes, limit) that returns the smallest number of batches needed to upload every file.
Input: sizes = [3,5,3,4], limit = 5 Output: 4
No two files fit together: the smallest pair, 3 + 3, is 6. So each file needs its own batch.
Input: sizes = [1,2,2,3], limit = 4 Output: 2
Batch 1 + 3 and 2 + 2.
0 <= sizes.length <= 500001 <= sizes[i] <= limit <= 30000Run 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 #102 Two-File Upload Batches. 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.