43
1
Given a non-negative integer skyline height list, answer how many uninterrupted 1-unit-high horizontal brush strokes are needed to cover it.
[1,3,2,1,2,1,5,3,3,4,2]
, visualised as:
5
5 4
3 5334
32 2 53342
13212153342
needs nine brush strokes:
1
2 3
4 5555
66 7 88888
99999999999
Examples
[1,3,2,1,2,1,5,3,3,4,2]
→ 9
[5,8]
→ 8
[1,1,1,1]
→ 1
[]
→ 0
[0,0]
→ 0
[2]
→ 2
[2,0,2]
→ 4
[10,9,8,9]
→ 11
For interested high-rep users: Based on this as per this.
– Adám – 2019-02-04T11:22:57.4972So, all brush strokes are horizontal? – tsh – 2019-02-04T11:38:41.383
1@tsh Good point. Added. – Adám – 2019-02-04T11:46:32.917
It wasnt codegolf, but I had this question for an interview code test about a year ago. – luizfzs – 2019-02-06T22:19:34.390