Menu

3619. Count Islands With Total Value Divisible by K
šŸ“°

3619. Count Islands With Total Value Divisible by K

DEV Community: phpĀ·MD ARIFUL HAQUEĀ·about 17 hours ago
#gLXr6BYe
#devto#dev#grid#value#total
Reading 0:00
15s threshold

3619. Count Islands With Total Value Divisible by K

Difficulty: Medium

Topics: Senior , Array , Depth-First Search , Breadth-First Search , Union-Find , Matrix , Biweekly Contest 161

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 .

Example 1:

Input: grid = [[0,2,1,0,0],[0,5,0,0,5],[0,0,1,0,0],[0,1,4,7,0],[0,2,0,0,8]], k = 5

Output: 2

Explanation: The grid contains four islands.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.