Pregunta de entrevista de SpaceX

1 leetcode question, around medium difficulty