Home › Interview Questions › You need to create an m x m matrix (e.g., 3x3, 2x3…

You need to create an m x m matrix (e.g., 3x3, 2x3) and render it on the screen.

🟡 Medium Coding Junior level
1Times asked
Apr 2026Last seen
Apr 2026First seen

💡 Model Answer

To render a dynamic m x m matrix, first determine the value of m at runtime. Create a container element and set display: grid; with grid-template-columns: repeat(m, 1fr); and grid-template-rows: repeat(m, 1fr);. Then generate mm child elements in a loop, each representing a cell. For example, in React you could map over an array of length mm and render a div for each cell. Style the cells with borders or background colors to visualize the grid. This solution is O(m²) in time and space, which is optimal because you must render every cell. If performance becomes an issue for very large m, consider virtualizing the grid or using a canvas.

This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.

🎤 Get questions like this answered in real-time

Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers — invisible to screen sharing.

Get Assisting AI — Starts at ₹500