C# Stone Blocks
static int StoneBlocks(int[] h)
{
    var height = new List<int>();
    var index = 0;
    var blocks = 0;

    foreach (var i in h)
    {
        while (index > 0 && height[index - 1] > i)
        {
            index--;
        }
        if (index > 0 && height[index - 1] == i)
        {
            continue;
        }

        if (index < height.Count)
        {
            height[index] = i;
        }
        else
        {
            height.Add(i);
        }
        blocks++;
        index++;
    }

    return blocks;
}

This uses a stack of active heights and only counts a new block when the wall needs a new height segment.