Amazon Interview Question

Coding question about giving islands unique numbers.