If rows form around the Ka'bah while the prayer leader is outside:
• the congregation is generally valid even though people face different sides of the Ka'bah;
• the exception is a follower who stands closer to the Ka'bah than the prayer leader in the same directional sector as the prayer leader.
The relevant comparison is not simply who is closer to the Ka'bah anywhere in the circle; it is precedence in the prayer leader's own direction.