ION Group interview question

They asked a medium DSA question