Pregunta de entrevista de Even Financial

Solving a standard Leetcode medium/hard type question.