Swiggy interview question

Leetcode medium but could answer that