Question d’entretien chez Intertech (Turkey)

it was one of the medium difficulty algorithm questions on hackerrank