Pregunta de entrevista de DBS Bank

Coding question and how to solve the question