You are given a 2D grid of characters '0' and '1', where '1' represents land and '0' represents water. An island is a maximal group of horizontally/vertically (4-directionally) adjacent land cells.
The size of an island is the number of land cells in that island.
You are also given an integer array queries, where each element is a size to query.
Return an integer array ans of the same length as queries, where ans[i] equals the number of islands in the grid whose size is exactly queries[i].
If the grid contains:
Then for queries = [10, 1, 2, 3], return ans = [2, 0, 5, 0].
1 <= rows, cols <= 2000
(or smaller depending on the language/time limit)
grid[r][c] ∈ {'0','1'}
1 <= queries.length <= 2e5
queries
may contain duplicates; return counts for each position.