Pregunta de entrevista de Samsung Electronics

Leet Code Medium level question