Ariston interview question

the logic for the code was asked.