#3619
Count Islands With Total Value Divisible by K
medium · 56.3% accepted · 64 likes · top 50%
array · depth-first search · breadth-first search · union-find · matrix
Description
You are given an m x n matrix grid and a positive integer k. An island is a group of positive integers (representing land) that are 4-directionally connected (horizontally or vertically).
The total value of an island is the sum of the values of all cells in the island.
Return the number of islands with a total value divisible by k.
Solution