ION Group Interview Question

They asked a medium DSA question