Pregunta de entrevista de ByteDance

1 leetcode medium, with extended question