Find number of horizontal brush strokes to paint a skyline
With every height drop by 1 point, a line ends. So you just need to calculate the sum of height drops. Don't forget to account for the last height. You could also do the same thing from the other end (every height increase starts a line).

def skyline(heights):
  diffs = [e1 - e2 for e1, e2 in zip(heights, heights[1:])]
  return sum(diff for diff in diffs if diff &gt; 0) + heights[-1]




Some remarks on your code:


copy = [a for a in A] can be rewritten as copy = A.copy()
some parentheses in (copy[i] &gt; 0) and ((i+1 == len(copy)) or (copy[i+1] == 0)) can be omitted:

if copy[i] > 0 and (i+1 == len(copy) or copy[i+1] == 0):
you can use enumerate in the for loop:


for i, elem in enumerate(copy):
&nbsp;&nbsp;if elem > 0 and (i+1 == len(copy) or copy[i+1] == 0):
&nbsp;&nbsp;&nbsp;&nbsp;strokes += 1
&nbsp;&nbsp;if elem > 0:
&nbsp;&nbsp;&nbsp;&nbsp;copy[i] -= 1

the ifs can be merged:


for i, elem in enumerate(copy):
&nbsp;&nbsp;if elem > 0:
&nbsp;&nbsp;&nbsp;&nbsp;copy[i] -= 1
&nbsp;&nbsp;&nbsp;&nbsp;if i+1 == len(copy) or copy[i+1] == 0:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strokes += 1