Let’s first number the places as shown in the figure-
We can see that inmate 5 sees 0 people in front of him. So, he must be standing at the extreme and facing the same direction i.e. north when standing in front or south when standing at last.
Similarly, inmate 6 sees 7 people. So, he must stand at P facing south or at W facing north.
Now, there are 2 people who see 6 people in front of them. So, they must be facing opposite direction (i.e. one who stands at Q faces south and one who stands at V faces north) and stand at one place among Q and V.
Also, inmate 2 sees 2 people ahead of him while inmate 7 sees 5 people. So, they must be facing the same direction standing at one position among R and U.
Similarly, 3 and 4 must be standing at one position among S and T facing the same direction.
So, positions of the 8 inmates can be concluded as:
Let us now decide on the directions for each of them:
The person from Q must definitely be facing south. Apart from this, the person facing south will increase by 2. Since the number of inmates facing south was not more than four, the number of person facing south has to be 3. If positions P and W are facing south, all others will have to face north which is not possible as no three consecutive inmates faced the same direction. So, person on P and W must be facing north. So, one of the pair of R-U or S-T must be facing south. But when person on U faces north, three consecutive people i.e. U, V, and W must be facing north which is not possible. Thus, pair S-T must be facing south. In this way, we can figure out the whole arrangement-
We can see that inmate from cell 7 definitely faces south.