Codility's stonewall 100% solution - different paths such as if,else if,etc, do the same thing
Some of these branches can be eliminated. Let's see:

if (heightsStack.Count &gt; 0)
{
  if (heightsStack.Peek() &lt; H[height])
  {
    blocksCounter++;
    heightsStack.Push(H[height]);
  }
}
else
{
  blocksCounter++;
  heightsStack.Push(H[height]);
}


Here, there are two conditions where we execute the two common lines: heightsStack.Count &lt;= 0 or heightsStack.Peek() &lt; H[height]. Since Count  can't be negative, let's rewrite it as such:

if (heightsStack.Count == 0 || heightsStack.Peek() &lt; H[height])
{
  blocksCounter++;
  heightsStack.Push(H[height]);
}




if (heightsStack.Count &gt; 0)
{
  while (heightsStack.Count &gt; 0 &amp;&amp; heightsStack.Peek() &gt; H[height])
  {


The first if-statement is redundant. If heightStack.Count &gt; 0 is false, the while statement will be false as well. We would immediately fall through and end up at the if-statement in the section above. This if-statement would evaluate to true, since heightStack.Count == 0 still. And it would execute the two common lines.

This would leave the body of the for-loop as follows:

while (heightsStack.Count &gt; 0 &amp;&amp; heightsStack.Peek() &gt; H[height])
{
  heightsStack.Pop();
}
if (heightsStack.Count == 0 || heightsStack.Peek() &lt; H[height])
{
  blocksCounter++;
  heightsStack.Push(H[height]);
}


Note, that we only have one branch with the two common lines.



There's one last thing. You're using a for-loop, and only using the looped variable to index directly. Instead, consider using a foreach loop:

public int solution(int[] H)
{
  Stack&lt;int&gt; heightsStack = new Stack&lt;int&gt;();
  int blocksCounter = 0;

  foreach(int height in H)
  {
    while (heightsStack.Count &gt; 0 &amp;&amp; heightsStack.Peek() &gt; height)
    {
      heightsStack.Pop();
    }
    if (heightsStack.Count == 0 || heightsStack.Peek() &lt; height)
    {
      blocksCounter++;
      heightsStack.Push(height);
    }
  }
  return blocksCounter;
}




As far as algorithm goes, you do what I would have come up with, so I have nothing more to say about that.