IBM Interview Question

It was an online coding round.