Question bank › Matrix
Dsa Matrix Medium

Adjacent Matrix Count

Given a rectangular matrix of 0s and 1s, count the number of cells that are adjacent (horizontally or vertically) to at least one '1'. Input format: - The first line contains two integers m and n (1 <= m, n <= 50), the number of rows and columns. - The next m lines each contain n integers (0 or 1) separated by spaces. Output format: - A single integer representing the count of cells adjacent to '1's. Example: Input: 3 3 0 0 0 1 0 0 0 0 1 Output: 5

Key concepts

matrixadjacencycounting

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.