# 305. Number of Islands II {%hackmd theme-dark %} CIT country infructure team west -> east x, y = CIT.build() MxN 2x3 day1: (2,0) day2: (2,0) day5 (2,2) MxN 3x5 row1: row2 row3: 5 time: t, M x N grid TC: O(tmn) -- [ [*0, 1, 0^] L [*0, 0, 0^]] R check find(L) == find(R) [ [0, 1, 2] [0, 0, 0]] [ [1, 1, 0] [0, 1, 0]] [ [1, 1, 0] [0, 1, 1]] ---- L [ [L, 1, R] R [L, 4, R]] ```cpp= int whenToFinish(int m, int n, CIT &cit) { for (int t = 0; ; t++) { auto &[x, y] = cit.build(); } 1 2 5 4 3 ``` [1 2 3 6 7 8] [1 2 3] [1 2] [2 3] [1] [2] [3] => sum [6 7 8 ] ... => sum [1 2 3 4] => 10 [2 3 4] => 10 -1 ###### tags: `mock interview` `面試`