Watch a hollow pyramid print in stars: only the two slanted edges and the base, from one condition on each cell of the nested loop.
About this algorithm
The hollow pyramid prints only the outline of the pyramid: one star at the top, two slanted edges going down, and a solid last row. Everything inside is blank.
Try it after the pyramid and the hollow square. The pyramid asks whether a column is inside the row's range; the hollow square asks whether a cell is on an edge. The hollow pyramid joins the two: the pyramid's shape with the hollow square's kind of test.
n rows and 2n - 1 columns, with the middle column at n - 1.
On row i the edges sit i columns either side of the middle, so a cell is on an edge when |j - (n - 1)| == i.
The last row, i == n - 1, is solid. A cell is a star when it is on an edge or on that row.
A 4 by 7 grid. Row 0 has one star in the middle, rows 1 and 2 have two stars each, and row 3 is seven stars. That is 12 stars and 16 spaces in 28 cells.
On row 0 both edges are 0 columns from the middle, so they land on the same cell. That is why the edge test needs no special case for the tip.
The solid pyramid tests |j - (n - 1)| <= i. Changing <= to == keeps only the edges, and the extra i == n - 1 puts the base back.
Time: every cell of the n by (2n - 1) grid gets one test, about 2n² in total. Space: the test needs only i, j and n.