Swiggy Interview Question

Leetcode medium but could answer that