Pregunta de entrevista de TUQ

Solve this LeetCode Easy, then make it arbitrary.