Fi Money interview question

Rotten oranges leetcode medium problem