Pregunta de entrevista de IBM

Leetcode problem of medium difficulty