Python Stone Blocks
def stone_blocks(h: list[int]) -> int:
height: list[int] = []
index = 0
blocks = 0
for i in h:
while index > 0 and height[index - 1] > i:
index -= 1
if index > 0 and height[index - 1] == i:
continue
if index < len(height):
height[index] = i
else:
height.append(i)
blocks += 1
index += 1
return blocks
This uses a stack of active heights and only counts a new block when the wall needs a new height segment.