Pregunta de entrevista de Infosys

Java coding question (easy to medium)