All perfect praise be to Allah, The Lord of the Worlds. I testify that there is none worthy of worship except Allah, and that Muhammad is His slave and Messenger.
It is permissible for you to follow the Imam who is in the mosque while you are praying outside the mosque, provided that you see the Imam or those who see him.
Some jurists are even more lenient about this matter and are of the view that it is permissible to follow the Imam as long as following him is practically possible (like being able to hear him without the ability to see him, for example).
In any case, your prayer inside the mosque is better and more rewardable.
Allah knows best.