We are given the amount of work of one builder (1 wall), and the amount of time he spent working (3 hours). Therefore his output is $\frac{1}{3}$ of a wall in an hour. Since the question involves two builders, the output of the two of them together is $2 \cdot \frac{1}{3}=\frac{2}{3}$ walls per hour.
We are also given the amount of work which the two builders must do $-5$ walls. We can therefore calculate the amount of time they will need: $t=\frac{5}{\frac{2}{3}}=5 \cdot \frac{3}{2}=\frac{15}{2}=7 \frac{1}{2}$. Thus, they will need $7 \frac{1}{2}$ hours to build the walls.