Maybe Ghandi Would Have Desired Baptism Had He Known
Can a person such as Ghandi obtain salvation?
The short answer is yes. But there are certain conditions that must be met. The Catechism of the Catholic Church states,
We must hold that the Holy Spirit offers to all the possibility of being made partakers, in a way known to God, of the Paschal mystery. Every man who is ignorant of the gospel of Christ and of his Church, but seeks the truth and does the will of God in accordance with his understanding of it, can be saved. It may be supposed that such persons would have desired baptism explicitly if they had known its necessity (1260, emphasis added).
This teaching is also found in Lumen Gentium from the Second Vatican Council:
Those who, through no fault of their own, do not know the gospel of Christ or his Church but who nevertheless seek God with a sincere heart, and, moved by grace, try in their actions to do his will as they know it through the dictates of their conscience—those too may achieve eternal salvation (LG, 16, emphasis added).
As to who fits this bill, for example, Mahatma Ghandi, only God knows.