Talabat interview question

The question was a dynamic prog question