Coding Problems on Matrix Data Structure Last Updated : 23 Aug, 2024 Comments Improve Suggest changes Like Article Like Report Matrix are a fundamental data structure with vast applications in computer science. This article will explore a variety of coding problems that uses the matrix data structure. Through these hands-on exercises, readers will develop practical skills in matrix manipulation and algorithm implementation. From basic operations to more advanced matrix-based techniques, this collection of problems aims to build the reader's expertise in working with this powerful data structure. Practice Problems on the Matrix Data Structure:Rotate Matrix ElementsInplace rotate square matrix by 90 degrees | Set 1Rotate a matrix by 90 degree without using any extra space | Set 2Rotate a Matrix by 180 degreeRotate each ring of matrix anticlockwise by K elementsTurn an image by 90 degreeCheck if all rows of a matrix are circular rotations of each otherSort the given matrixFind the row with maximum number of 1sFind median in row wise sorted matrixMatrix Multiplication | RecursiveProgram to multiply two matricesProgram for scalar multiplication of a matrixProgram to print Lower triangular and Upper triangular matrix of an arrayFind distinct elements common to all rows of a matrixPrint a given matrix in spiral formFind maximum element of each row in a matrixFind unique elements in a matrixShift matrix elements row-wise by kDifferent Operations on MatricesPrint a given matrix in counter-clock wise spiral formSwap major and minor diagonals of a square matrixMaximum path sum in matrixSquares of Matrix Diagonal ElementsMove matrix elements in given direction and add elements with same valueSorting rows of matrix in ascending order followed by columns in descending orderSum of middle row and column in MatrixRow-wise vs column-wise traversal of matrixRotate the matrix right by K timesProgram to check idempotent matrixProgram to check Involutory MatrixInterchange elements of first and last rows in matrixPrint matrix in zag-zag fashionRow wise sorting in 2D arrayProgram for Markov matrixProgram to check diagonal matrix and scalar matrixSort the matrix row-wise and column-wiseFind the number of islandsMagic Square | Even OrderMagic SquareCheck given matrix is magic square or notCheck given matrix is magic square or notKronecker Product of two matricesCount sub-matrices having sum divisible ‘k’Diagonally Dominant MatrixMinimum operations required to make each row and column of matrix equalsCount frequency of k in a matrix of size n where matrix(i, j) = i+jGiven 1’s, 2’s, 3’s ……k’s print them in zig zag way.Number of cells a queen can move with obstacles on the chessboradMaximum product of 4 adjacent elements in matrixMinimum flip required to make Binary Matrix symmetricProgram to check if matrix is lower triangularProgram to check if matrix is upper triangularFrequencies of even and odd numbers in a matrixCenter element of matrix equals sums of half diagonalsProgram for Identity MatrixProgram to swap upper diagonal elements with lower diagonal elements of matrix.Sparse Matrix RepresentationsWays of filling matrix such that product of all rows and all columns are equal to unityMirror of matrix across diagonalFind if there is a rectangle in binary matrix with corners as 1Find all rectangles filled with 0Shortest distance between two cells in a matrix or gridCounting sets of 1s and 0s in a binary matrixSearch in a row wise and column wise sorted matrixCreate a matrix with alternating rectangles of O and XZigzag (or diagonal) traversal of MatrixInplace (Fixed space) M x N size matrix transpose | UpdatedMinimum cost to sort a matrix of numbers from 0 to n^2 – 1Unique cells in a binary matrixCount entries equal to x in a special matrixCheck if a given matrix is sparse or notRow-wise common elements in two diagonals of a square matrixCheck if sums of i-th row and i-th column are same in matrixFind row number of a binary matrix having maximum number of 1sProgram to check if a matrix is symmetricFind if a 2-D array is completely traversed or not by following the cell valuesProgram to Print Matrix in Z formPrint all palindromic paths from top left to bottom right in a matrixPossible moves of knightEfficiently compute sums of diagonals of a matrixBoundary elements of a MatrixPrint a matrix in a spiral form starting from a pointPrint matrix in snake patternProgram to Interchange Diagonals of MatrixFind difference between sums of two diagonalsConstruct Ancestor Matrix from a Given Binary TreeConstruct tree from ancestor matrixCircular Matrix (Construct a matrix with numbers 1 to m*n in spiral way)Program for Sudoku GeneratorProgram for Conway’s Game Of LifeMaximum sum of hour glass in matrixMaximum and Minimum in a square matrix.Print matrix in antispiral formProgram to find Normal and Trace of a matrixSort a Matrix in all way increasing orderMinimum operations required to set all elements of binary matrixPrint a given matrix in reverse spiral formC Program To Check whether Matrix is Skew Symmetric or notSum of matrix element where each elements is integer division of row and columnSparse Matrix and its representations Find number of transformation to make two Matrix EqualForm coils in a matrixSum of matrix in which each element is absolute difference of its row and column numbersCheck horizontal and vertical symmetry in binary matrixMaximum determinant of a matrix with every values either 0 or nSum of both diagonals of a spiral odd-order square matrixFind pair of rows in a binary matrix that has maximum bit differenceFind all permuted rows of a given row in a matrixFind perimeter of shapes formed with 1s in binary matrixPrint cells with same rectangular sums in a matrixPrint matrix in diagonal patternMaximum difference of sum of elements in two rows in a matrixFind pairs with given sum such that elements of pair are in different rowsTotal coverage of all zeros in a binary matrixReplace every matrix element with maximum of GCD of row or columnCount all sorted rows in a matrixQueries in a MatrixMaximum XOR value in matrixMaximum mirrors which can transfer light from bottom to rightDirection at last square blockPrint K’th element in spiral form of matrixFind if given matrix is Toeplitz or notCount zeros in a row wise and column wise sorted matrixCount Negative Numbers in a Column-Wise and Row-Wise Sorted MatrixFind size of the largest ‘+’ formed by all ones in a binary matrixReturn previous element in an expanding matrixPrint n x n spiral matrix using O(1) extra spaceShortest path in a Binary MazeFind orientation of a pattern in a matrixFind a specific pair in MatrixPrint maximum sum square sub-matrix of given sizeCommon elements in all rows of a given matrixIn-place convert matrix in specific orderA Boolean Matrix QuestionGiven a Boolean Matrix, find k such that all elements in k’th row are 0 and k’th column are 1.Print unique rows in a given boolean matrixFind the largest rectangle of 1’s with swapping of columns allowedValidity of a given Tic-Tac-Toe board configurationSubmatrix Sum QueriesProgram for Rank of MatrixMaximum size rectangle binary sub-matrix with all 1sMaximum size square sub-matrix with all 1sFind sum of all elements in a matrix except the elements in row and/or column of given cell?Count number of islands where every island is row-wise and column-wise separatedFind a common element in all rows of a given row-wise sorted matrixGiven a matrix of ‘O’ and ‘X’, replace ‘O’ with ‘X’ if surrounded by ‘X’Given a matrix of ‘O’ and ‘X’, find the largest subsquare surrounded by ‘X’Flood fill Algorithm – how to implement fill() in paint?Print all elements in sorted order from row and column wise sorted matrixGiven an n x n square matrix, find sum of all sub-squares of size k x kProgram to find transpose of a matrixC program for addition of two matricesC program for subtraction of matricesCollect maximum points in a grid using two traversalsCollect maximum coins before hitting a dead endNumber of paths with exactly k coinsFind length of the longest consecutive path from a given starting characterFind the longest path in a matrix with given constraintsMinimum Initial Points to Reach DestinationDivide and Conquer | Set 5 (Strassen’s Matrix Multiplication)Dynamic Programming | Set 27 (Maximum sum rectangle in a 2D matrix)Quick Links : 'Practice Problems' on Arrays 'Quizzes' on Arrays 'Video Tutorials' on Arrays Comment More infoAdvertise with us Next Article Coding Problems on Matrix Data Structure H harendrakumar123 Follow Improve Article Tags : Matrix DSA Practice Tags : Matrix Similar Reads DSA Tutorial - Learn Data Structures and Algorithms DSA (Data Structures and Algorithms) is the study of organizing data efficiently using data structures like arrays, stacks, and trees, paired with step-by-step procedures (or algorithms) to solve problems effectively. Data structures manage how data is stored and accessed, while algorithms focus on 7 min read Quick Sort QuickSort is a sorting algorithm based on the Divide and Conquer that picks an element as a pivot and partitions the given array around the picked pivot by placing the pivot in its correct position in the sorted array. It works on the principle of divide and conquer, breaking down the problem into s 12 min read Merge Sort - Data Structure and Algorithms Tutorials Merge sort is a popular sorting algorithm known for its efficiency and stability. It follows the divide-and-conquer approach. It works by recursively dividing the input array into two halves, recursively sorting the two halves and finally merging them back together to obtain the sorted array. Merge 14 min read Bubble Sort Algorithm Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in the wrong order. This algorithm is not suitable for large data sets as its average and worst-case time complexity are quite high.We sort the array using multiple passes. After the fir 8 min read Data Structures Tutorial Data structures are the fundamental building blocks of computer programming. They define how data is organized, stored, and manipulated within a program. Understanding data structures is very important for developing efficient and effective algorithms. What is Data Structure?A data structure is a st 2 min read Breadth First Search or BFS for a Graph Given a undirected graph represented by an adjacency list adj, where each adj[i] represents the list of vertices connected to vertex i. Perform a Breadth First Search (BFS) traversal starting from vertex 0, visiting vertices from left to right according to the adjacency list, and return a list conta 15+ min read Binary Search Algorithm - Iterative and Recursive Implementation Binary Search Algorithm is a searching algorithm used in a sorted array by repeatedly dividing the search interval in half. The idea of binary search is to use the information that the array is sorted and reduce the time complexity to O(log N). Binary Search AlgorithmConditions to apply Binary Searc 15 min read Insertion Sort Algorithm Insertion sort is a simple sorting algorithm that works by iteratively inserting each element of an unsorted list into its correct position in a sorted portion of the list. It is like sorting playing cards in your hands. You split the cards into two groups: the sorted cards and the unsorted cards. T 9 min read Dijkstra's Algorithm to find Shortest Paths from a Source to all Given a weighted undirected graph represented as an edge list and a source vertex src, find the shortest path distances from the source vertex to all other vertices in the graph. The graph contains V vertices, numbered from 0 to V - 1.Note: The given graph does not contain any negative edge. Example 12 min read Selection Sort Selection Sort is a comparison-based sorting algorithm. It sorts an array by repeatedly selecting the smallest (or largest) element from the unsorted portion and swapping it with the first unsorted element. This process continues until the entire array is sorted.First we find the smallest element an 8 min read Like