Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6454 |

@blackshadows | 6380 |

@mb1973 | 5710 |

@Quandray | 5245 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 5046 |

@sanjay05 | 3762 |

@kirtidee18 | 3709 |

@mantu_singh | 3556 |

@marius_valentin_dragoi | 3523 |

@sushant_a | 3459 |

Complete Leaderboard | |

Handle | Score |

@cfwong8 | 1285 |

@gurshehzadsingh | 1052 |

@pritsahkar2000 | 812 |

@nithinreddy3210 | 801 |

@satyamchhatrala | 800 |

@iib2019024 | 745 |

@mohanreddy8847 | 704 |

@iamchaitanyahegde | 662 |

@workit | 646 |

@shafeeq3543 | 645 |

@AkashLahoty | 642 |

Complete Leaderboard |

Geek has a rosarium and it has **N*M** slots, some of them are empty and some of them have roses. Given **N*M **character array consists of **0's** and **1's**. **0** represents an empty spot and **1** represents a rose. The task is to find the maximum number of adjacent roses in geek's rosarium. For a spot **(i, j)** adjacent spots are **(i+1, j), (i-1, j), (i, j-1), (i, j+1), (i-1, j-1), (i-1, j+1), (i+1, j-1), **and **(i+1, j+1).**

**Input: **

1. The first line of the input contains a single integer* * **T** denoting the number of test cases. The description of **T** test cases follows.

2. The first line of each test case contains two space-separated integers **N **and** M.**

3.** **Next **N** lines consist of **M** characters.

**Output:** For each test case, print the maximum number of adjacent roses.

**Constraints:**

1. 1 <= T <= 100

2. 1 <= N, M <= 100

3. '0' <= arr[i][j] <= '1'

**Example:
Input:**

2

2 2

10

01

3 4

1001

0011

0101

**Output:**

2

5

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Geeks's Garden

...