Number of Islands II
CodingPhone Screen, OnsiteSoftware Engineer, Machine Learning EngineerReported Mar, 2026High Frequency
Examples
Example 1:
Input: m = 3, n = 3, positions = [[0,0],[0,1],[1,2],[2,1],[1,1]]
Output: [1,1,2,3,1]
Explanation:
Example 2:
Input: m = 1, n = 1, positions = [[0,0]]
Output: [1]