How to Solve Building Height Puzzles: Count What You Can See

This article was written with AI and may contain mistakes. Found one? Tell us.

By Riddle10 Editorial Published 11 min read

To solve a building-height puzzle, read each edge clue as the number of buildings you would see from that side, knowing that a taller building hides every shorter one behind it. A clue of 1 puts the tallest building right at that edge, a clue equal to the grid size means the heights rise one step at a time from that edge, and every other clue limits how tall the first buildings can be.

After those clues, the grid fills like any no-repeat grid: each height turns up exactly one time per row and one time per column. This guide shows how visibility works, what each clue tells you, a six-step method, one grid solved in full and a practice grid with its answer.

What is a building-height puzzle?

The puzzle is a square grid seen from above, like a block of a city plan. Each cell holds one building, and its height is a whole number between 1 and the grid size. In a four by four grid the heights are 1, 2, 3 and 4.

Two rules apply inside the grid:

  • Every row holds each height exactly once.
  • Every column holds each height exactly once.

Numbers sit outside the grid, at the ends of some rows and columns. Each one says how many buildings a person standing at that point, looking along the line, could see. A good puzzle has exactly one solution.

How does visibility work?

Imagine standing at the left end of a row and looking right. The first building is always visible. After that, a building is visible only if it is taller than every building in front of it. A shorter building standing behind a taller one is hidden.

Take a row of four with heights 2, 4, 1, 3 read from the left. You see the 2, then the 4 rises above it. The 1 and the 3 both stand behind the 4, so they are hidden. The left clue for this row would be 2.

Now walk to the right end and look back. The row reads 3, 1, 4, 2. You see the 3, the 1 hides behind it, the 4 rises above it, and the 2 hides behind the 4. The right clue is also 2.

Notice that the tallest building is always visible from both ends. Everything else is visible from one end at most, or from neither.

What do mathematicians call a visible building?

In the mathematics of arrangements, a visible building has a name: it is a record, an entry larger than everything before it when the line is read in one direction [1].

A paper published on 28 February 2010 calls an entry a right-maximal value when it is larger than every entry to its right [1]. Read a row from its right-hand end, and these are exactly the buildings you can see.

The same paper works through the arrangement 2 5 3 4 1 and lists its right-maximal values as 1, 4 and 5 [1]. As a row of buildings, that means a person at the right end sees three of them, and from the left end only the 2 and the 5 stand out.

The paper also lists eight kinds of record, built from three choices: reading right to left or left to right, looking for maximum or minimum entries, and noting the position or the value [1]. In its example arrangement 5 1 6 4 2 3, the left-to-right maximum values are 5 and 6, and the right-to-left maximum values are 3, 4 and 6 [1].

Building-height puzzles use only the maximum kinds, read from both ends of every row and column. The abstract of that paper states its main result: two statistics of an arrangement, called major codes and inversion codes, are equidistributed, or spread out in the same way, over a set of arrangements with prescribed descent positions and right-to-left records [1]. The puzzle borrows the vocabulary of that work rather than its results.

One small observation in the paper is directly useful when solving: every position of a right-to-left record, apart from the last place, is a descent, a spot where the next entry is smaller [1]. In grid terms, a building that can be seen from the right, other than the one at the very edge, is always taller than its right-hand neighbour.

How does the grid relate to a Latin square?

Once solved, the grid is a Latin square of heights, with no height repeated along any line. A paper published on 1 March 2013 notes that a Latin square can also be read as a set of triples, each naming a row, a column and the symbol placed where they meet [2].

That triple view is a handy way to think while solving. Every deduction you make fixes one triple, a row, a column and a height, and the no-repeat rule then strikes that height from the rest of the row and column. The edge clues are extra conditions laid on top, and they are what make a nearly empty grid solvable.

What can each clue tell you?

Clue from one edgeWhat it means in a grid of size nExample in a four by four grid
1The tallest building stands in the first cellThe cell at that edge is 4
nHeights rise one step at a time from that edgeThe line reads 1, 2, 3, 4
c, in generalThe first cell is at most n minus c plus 1A clue of 3 caps the first cell at 2
c, one cell further inThat cell is at most one more than the first capA clue of 3 caps the second cell at 3
Clues at both ends of one lineAt most one of them is a clue of one, and together they never exceed the line length by more than one, since only the tallest building is seen from both endsTwo 3s, or two 1s, can never face each other

The cap rule comes from counting what must still be seen. If the first building were too tall, there would not be enough taller buildings left behind it to reach the clue.

How many orders fit each clue?

Clues near the middle allow many orders, while the extreme clues allow very few. We counted these ourselves, with a short computer program that lists every order of the buildings in one line:

Buildings in the lineClue 1Clue 2Clue 3Clue 4Clue 5All orders
Four61161not possible24
Five245035101120

So a clue equal to the grid size fixes the whole line at once, and a clue of 1 fixes one cell. A clue of 2 in a four-building line still leaves eleven orders, which is why it does little on its own. Its value shows up when another clue or a few placed heights cut the choices down.

What steps should you follow?

  1. Fill the extremes. Write in every line with a clue equal to the grid size, and the tallest building beside every clue of 1.
  1. Apply the caps. Beside each other clue, note the largest height the first cell or two can hold.
  1. Strike repeats. Whenever you place a height, remove it from the rest of its row and column.
  1. Test short lists. When a line has two or three cells left, write out each possible order and count what is visible from each clued end. Keep only the orders that match.
  1. Find the last spot. In any row or column, if a height has only one cell left where it can go, place it there.
  1. Check every clue. Read each clued line from its end and count the visible buildings once more.

How do the steps work on a real grid?

Here is an original puzzle. Columns are numbered 1 to 4 from left to right and rows 1 to 4 from top to bottom. Clues above the grid are seen from the top, clues below from the bottom, and clues at the sides from the left or right end of that row.

2
····
····
1····3
····
43

So there are five clues: 2 at the top of column 1, 4 at the bottom of column 2, 3 at the bottom of column 3, 1 at the left of row 3 and 3 at the right of row 3. Work it out yourself before reading further.

Step 1: the extremes. The 4 below column 2 means all four buildings are seen from the bottom, so the heights rise from the bottom up. Reading down, column 2 is 4, 3, 2, 1. The 1 at the left of row 3 means the tallest building is at that edge, so row 3, column 1 is 4.

Step 2: row 3. Row 3 now starts 4, 2, and its last two cells hold 1 and 3. Test both orders from the right-hand end, where the clue is 3.

If the row ends 1, 3, it reads 3, 1, 2, 4 from the right, and only the 3 and the 4 are visible: two, not three. If the row ends 3, 1, it reads 1, 3, 2, 4 from the right, and the 1, the 3 and the 4 are visible: three. So row 3 is 4, 2, 3, 1. Those three visible heights are the right-to-left records of the row.

Step 3: the cap in column 3. The clue below column 3 is 3, so its bottom cell is at most 2. Column 3 already has a 3, and row 4 already has a 1 in column 2, so the bottom cell of column 3 is 2.

The top two cells of column 3 hold 1 and 4, and both orders give three visible buildings from the bottom. Row 1 already has its 4 in column 2, so row 1, column 3 is 1 and row 2, column 3 is 4.

Step 4: column 1. Row 4 already holds 1 and 2, and column 1 already holds 4, so row 4, column 1 is 3.

The top two cells of column 1 hold 1 and 2. Test them against the clue of 2 at the top. Reading down 1, 2, 4, 3, you see the 1, the 2 and the 4: three, which is wrong. Reading down 2, 1, 4, 3, you see the 2 and the 4: two, which is right. So column 1 is 2, 1, 4, 3.

Step 5: the last spots. Each row now has one empty cell, in column 4. Row 1 needs 3, row 2 needs 2 and row 4 needs 4. Column 4 reads 3, 2, 1, 4, with no repeats.

Step 6: the check.

Column 1Column 2Column 3Column 4
Row 12413
Row 21342
Row 34231
Row 43124

From the top of column 1 you see 2 and 4. From the bottom of column 2 you see all four. From the bottom of column 3 you see 2, 3 and 4. From the left of row 3 you see only the 4, and from the right you see 1, 3 and 4. All five clues hold.

We checked by computer, trying every possible four by four grid with no repeats, that this is the only grid that fits the clues.

Which mistakes should you avoid?

  • Counting hidden buildings. A building counts only if it is taller than everything in front of it, not merely taller than its neighbour.
  • Forgetting the far end. A line read from the left and from the right gives two different counts. Use the clue for the end it sits on.
  • Treating a clue of 2 as strong. On its own it allows many orders. Wait until the line has only a few cells left, then test them.
  • Skipping the caps. The first-cell limit is the cheapest deduction in the puzzle, and it can decide a cell straight away.
  • Placing a repeat. After each placement, scan its row and column before moving on.

Can you solve this practice grid?

This four by four grid has only four clues: 4 at the left of row 1, 4 at the right of row 3, 3 at the bottom of column 2 and 3 at the bottom of column 4.

4····
····
····4
····
33

Fill the grid before reading the answer.

Answer: the rows from top to bottom are 1, 2, 3, 4; then 2, 4, 1, 3; then 4, 3, 2, 1; then 3, 1, 4, 2.

Here is the reasoning. The two 4 clues fix row 1 as 1, 2, 3, 4 and row 3 as 4, 3, 2, 1.

Column 2 now has 2 at the top and 3 in row 3, so rows 2 and 4 hold 1 and 4. From the bottom, putting 1 in row 4 shows the 1, the 3 and the 4, which is three, while putting 4 there shows only the 4, so row 4, column 2 is 1.

Column 4 has 4 at the top and 1 in row 3, so rows 2 and 4 hold 2 and 3. From the bottom, 2 then 1 then 3 then 4 shows three buildings, while 3 then 1 then 2 then 4 shows only two, so row 4, column 4 is 2.

The no-repeat rule then fills the rest: row 2 is 2, 4, 1, 3 and row 4 is 3, 1, 4, 2. We checked by computer that there is no other answer.

Where can you practise seeing what is hidden?

Building-height grids train one habit above all: picturing what stands in front and what it hides. Try a live riddle called Count Every Cube, which asks how many cubes are in the stack.

References

  1. Dzhumadil'daev, A. (2010, February 28). MacMahon's Theorem for a Set of Permutations with Given Descent Indices and Right-Maximal Records. The Electronic Journal of Combinatorics, 17(1), R34. DOI 10.37236/306
  2. Abel, R. J. R., Cavenagh, N. J., & Kuhl, J. (2013, March 1). Induced Subarrays of Latin Squares Without Repeated Symbols. The Electronic Journal of Combinatorics, 20(1), P44. DOI 10.37236/2372

building height puzzles logic puzzles visibility clues grid puzzles step by step solving methods

More reading