Pregunta de entrevista de Amazon

One DSA coding problem and it was difficult