MulticoreWare interview question

Island perimeter program question from the leetcode platform