ShopUp interview question

Leetcode island problem. It's an medium level problem of leetcode.