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, sallallahu ʻalayhi wa sallam, is His slave and Messenger.
What you did was not cheating, because the one who overhears the answer without seeking it is not a cheater. Shaykh Ibn ʻUthaymeen,
, when asked a similar situation, said, “This falls under the category of unsolicited help. There is no harm in writing down this answer, even if he did not know it before overhearing it; he is allowed to write it because he neither tried to cheat nor actually cheated.”
Hence, you bear no sin for what you mentioned, and it does not affect the validity of your studies or your future work, so ignore your doubts and obsessive thoughts about this matter. What we mentioned in fatwa 115236 does not apply to your case; rather, these are only obsessive whisperings that must be ignored. You should embrace your life and your studies and seek refuge with Allah from the devil whenever such thoughts occur to you.
Allah knows best.