Pregunta de entrevista de AMD

asked a leetcode medium question