Fence Painting

Asked at GoogleOnsite

Reported by the problem's creator, not verified

A fence is a row of planks, each 1 unit wide. Every unit of every plank must be painted, and each stroke of the brush counts as one operation. Heights are whole units, so a plank of height 3 has rows 1, 2 and 3. A stroke may cover units that are already painted.

Examples

  1. Example 1

    Input: heights = [2,2,1,2,1]

    Output: 3

    Explanation: One horizontal stroke covers row 1 across all five planks. The height-1 plank splits row 2 into two runs, so two more strokes paint the three tall planks.

Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.
Import a question

Code

Loading editor…

Ln 1, Col 1

Start an attempt to use Coach.