Pregunta de entrevista de Toppan Ecquaria

Got paper test and if you do coding in Java, should be easy