Tap here to switch tabs
Problem
Submissions

Problem: Count Islands With Total Value Divisible by K

Try to solve the Count Islands With Total Value Divisible by K problem.

Statement

You are given an m×nm \times n integer matrix grid and an integer k.

An island is formed by connected cells with values strictly greater than 00, where connectivity is defined horizontally or vertically. You may assume all four edges of the grid are surrounded by 00.

The total value of an island is the sum of all cell values belonging to that island.

Return the total number of islands whose total value is divisible by k.

Constraints:

  • m ==== grid.length

  • n ==== grid[i].length

  • 1≤1 \leq m, n ≤1000\leq 1000

  • 1≤1 \leq m * n ≤105\leq 10^5

  • 0≤0 \leq grid[i][j] ≤106\leq 10^6

  • 1≤1 \leq k ≤106\leq 10^6

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Count Islands With Total Value Divisible by K

Try to solve the Count Islands With Total Value Divisible by K problem.

Statement

You are given an m×nm \times n integer matrix grid and an integer k.

An island is formed by connected cells with values strictly greater than 00, where connectivity is defined horizontally or vertically. You may assume all four edges of the grid are surrounded by 00.

The total value of an island is the sum of all cell values belonging to that island.

Return the total number of islands whose total value is divisible by k.

Constraints:

  • m ==== grid.length

  • n ==== grid[i].length

  • 1≤1 \leq m, n ≤1000\leq 1000

  • 1≤1 \leq m * n ≤105\leq 10^5

  • 0≤0 \leq grid[i][j] ≤106\leq 10^6

  • 1≤1 \leq k ≤106\leq 10^6