Question bank › Matrix
Dsa Matrix Easy

Matrix Color Regions

Given a matrix representing a grid of integers, identify the coloring regions. Two adjacent cells (4-directionally adjacent) belong to the same region if they have the same integer value. Return the number of distinct coloring regions in the matrix. Input Format: - The first line contains two integers, m and n. - The next m lines contain n integers each, representing the matrix. Output Format: - A single integer representing the number of distinct regions. Example: Input: 3 3 1 1 2 1 1 2 2 2 2 Output: 3

Key concepts

matrixflood fill

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 Praxari's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.