Pregunta de entrevista de Google

two leetcode mediums, not that hard