Fill in the blanks with words given within parentheses by applying appropriate tenses :
Yesterday while I _________ (travel) in a bus, I _______ (happen) to see a gentleman whom at first I _______ (think) I ___________ (not see) him before. Then I ________ (realize) that he _________ (be) a friend of mine during my school days.
My attempt : Yesterday while I was traveling in a bus, I happened to see a gentleman whom at first I thought I haven't seen him before. Then I realized that he had been a friend of mine during my school days.
The only thing which confuses me is the portion... "I thought I haven't seen him before." Grammarly app suggests that it should be "I thought I hadn't seen him before."
Can anybody please check it?