COUNTISL - How many Islands
You are given a simple map of an archipelago. Can you determine how many islands it shows?
The map consists of grid squares with characters, where '#' indicates land and '.' indicates water. Two land squares belong to the same island if they are neighbouring grid squares, which means their x coordinates and y coordinates differ by at most 1.
The first line of the input contains a number T ≤ 20 which indicates the number of test cases to follow.
Each test case starts with a line containing two numbers n and m (1 ≤ n,m ≤ 200), the number of rows and the number of columns of the grid, respectively. The following n lines contain m characters each and describe the map to be processed. You may assume that the map contains only characters '#' and '.', and that the border of the map consists only of water (character '.').
For each test case print in a line the number of islands shown on the corresponding map in the input.
Input: 2 1 1 . 6 4 .... ..#. .#.. .... .##. .... Output: 0 2
Nice problem , AC in one go , 0.01s
Getting NZEC. Java Code works on my system until the size 194*194, throws stackflowerror for anything above that. Is there any SUCCESSFUL submission in JAVA for this problem?
1 more dfs applic.
Getting WA. Some more test cases please