Pergunta de entrevista da empresa IBM

Leetcode problem of medium difficulty