Domanda di colloquio di Intertech (Turkey)

it was one of the medium difficulty algorithm questions on hackerrank