Pregunta de entrevista de Swiggy

Leetcode medium but could answer that