Pregunta de entrevista de Elastic

Leet code medium difficulty question, with a focus on the Java data type