tech-interview-handbook/questions/02-matrix-islands.md

761 B

id title topics difficulty source
2 Matrix Islands
array
depth-first-search
matrix
easy
https://leetcode.com/problems/number-of-islands/
https://leetcode.com/problems/max-area-of-island/
https://leetcode.com/problems/number-of-distinct-islands/

Question

'''
Given a matrix of 0s and 1s, count the number of islands present.

[[0,0,1],
 [0,0,0],
 [0,1,1]]

Answer: 2
'''

Follow Up

Given a matrix of 0s and 1s, find the size of the largest island present.

'''
[[0,0,1],
 [0,0,0],
 [0,1,1]]

Answer: 2

Follow Up II

Given a matrix of 0s and 1s, find the number of unique islands present present.

'''
[[1,0,1,0],
 [1,0,0,0],
 [0,1,1,0]]

Answer: 3

[[1,1,0,1],
 [0,0,0,0],
 [0,1,1,0]]

Answer: 2