Question bank › Matrix
Dsa Matrix Medium

Element Frequency Matrix

Given a 2D matrix of integers, return a 2D matrix where each element is replaced by the count of its occurrences in the original matrix. The output matrix should have the same dimensions as the input matrix. Input format: - The first line contains two integers, the number of rows 'n' and the number of columns 'm'. - The next 'n' lines each contain 'm' space-separated integers, which represent the elements of the matrix. Output format: - Print the resulting matrix with each row on a new line, elements separated by a single space. Example: Input: 3 3 1 2 1 2 3 2 3 1 3 Output: 2 2 2 2 2 2 2 2 2

Key concepts

matrixfrequencycounting

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.