Please quote the Hadith and reference regarding how a person spends most of his life doing the deeds of the people of Jannah, but at the end of his life, he commits Kufr and enters Jahannam. And another person does the deeds of the people of Jahannam but at the end of his life, he brings Iman.
You are probably referring to the following Hadith recorded in Sahih Bukhari and Sahih Muslim:
Rasulullah (sallallahu ‘alayhi wa sallam) said,
“[The way of creation of] a human being is put together in the womb of the mother in forty days, and then he becomes a clot of thick blood for a similar period, and then a piece of flesh for a similar period.Then Allah sends an Angel and he is commanded to record four commandments; his actions, his sustenance, his life span and whether he will [turn out to be] wretched or fortunate. Then the soul is blown into the infant. A person among you may [for his entire life] carry out the actions of a person destined for Jannah until there is only an arm span between him and Jannah, and then what is decreed for him will overtake him and he does the actions of someone destined for Jahannam. A person among you may do the actions of someone destined for Jahannam until there is only an arm span between him and Jahannam, and then what is decreed for him will overtake him and he will do the actions of someone destined for Jannah”
(Sahih Bukhari, Hadith: 3208 and Sahih Muslim, Hadith: 2643. Also see Sahih Bukhari, Hadith: 2898)
And Allah Ta’ala Knows best.
Answered by: Moulana Suhail Motala
Approved by: Moulana Muhammad Abasoomar
Checked by: Moulana Haroon Abasoomar