ByteDance interview question

Coding exercise about island question using BSF