Upstox interview question

Leetcode Rotten oranges question (medium)