The TransCompilator

Solved LeetCode program · 834 of 1,000

#1105 · Filling Bookcase Shelves

Medium Array chunk-17.md

Original English source

The thickness is a list of 1, 2, 2, 1, 1, 1, and 1. The tallness is a list of 1, 3, 3, 1, 1, 1, and 2. The shelf is 4. The count is 7. The costs is a list of 8 zeros. Set item 0 of costs to 0.
For every book from 1 to count.
Set item book of costs to 1000000. The width is 0. The height is 0. The start is book minus 1. The need is item start of thickness.
Repeat while start is at least 0 and need is at most shelf.
The thick is item start of thickness. The tall is item start of tallness. Add thick to width. If tall is more than height, set height to tall. The candidate is item start of costs plus height. If candidate is less than item book of costs, set item book of costs to candidate. Subtract 1 from start. If start is at least 0, The nextthick is item start of thickness, set need to width plus nextthick.

Show item count of costs.

Open in Playground Browse all 1,000 problems

Expected stdout

6