Answered by Ustadh Tabraze Azam
Question: Assalamu alaykum.
 Is it permissible to pray only two units of prayer (rakats) because you are a traveler, with the Imam praying four rakats because he is not a traveler?
Does saying your salams and ending before the Imam break the prayer?
 Is it permissible to pray a different prayer (I.e. dhur) with an Imam praying asr? Or praying a fard with the Imam praying sunnah?
Is the ruling different after the congregation prayer is over and you want to pray fard while the Imam is praying sunnah by himself?
Answer: Wa alaikum assalam wa rahmatullahi wa barakatuh
I pray that this finds you in the best of health and spirits, insha’Allah.
The basis in following an imam is that you must follow do so completely. Stopping the prayer early or praying a different prayer to his negate the meaning of ‘following’ or being a follower.
 No, you cannot end your prayer [as a traveler behind a resident] before the imam by saying the salams after two units (rak`ats). This would invalidate your prayer.
 No, it is not permissible to follow the imam by [a] intending a different prayer to his, for example, intending to pray `Asr behind an imam praying Zuhr, or [b] intending a stronger prayer than his, such as intending an obligatory prayer behind someone praying a voluntary or sunna prayer. Both of these would not be considered a valid prayer.
[`Ala’ al-Din `Abidin, al-Hadiyya al-`Ala’iyya]
And Allah alone gives success.
Checked & Approved by Faraz Rabbani