Matrix Interview Questions and Practice Problems

In this post, we have list out commonly asked interview questions that uses matrix data structure-


  1. Print Matrix in Spiral Order
  2. Create Spiral Matrix from given array
  3. Shift all matrix elements by 1 in Spiral Order
  4. Find Shortest path from source to destination in a matrix that satisfies given constraints
  5. Change all elements of row i and column j in a matrix to 0 if cell (i, j) has value 0
  6. Print diagonal elements of the matrix having positive slope
  7. Find all paths from first cell to last cell of a matrix
  8. Replace all occurrences of 0 that are not surrounded by 1 in a binary matrix
  9. In-place rotate the matrix by 90 degrees in clock-wise direction
  10. Count negative elements present in sorted matrix in linear time
  11. Report all occurrences of an element in row wise and column wise sorted matrix in linear time
  12. Calculate sum of all elements in a sub-matrix in constant time
  13. Find maximum sum K x K sub-matrix in a given M x N matrix
  14. Find maximum sum submatrix present in a given matrix
  15. Find probability that a person is alive after taking N steps on the island
  16. Count the number of islands
  17. Flood fill Algorithm
  18. Find shortest safe route in a field with sensors present
  19. Find all occurrences of given string in a character matrix
  20. Shortest path in a Maze | Lee algorithm
  21. Check if given matrix is Toeplitz matrix or not
  22. In-place rotate the matrix by 180 degrees
  23. Fill Binary Matrix with Alternating Rectangles of 0 and 1
  24. Find all common elements present in every row of given matrix
  25. Construct a Binary Tree from Ancestor Matrix
  26. Find common elements present in all rows of a matrix
  27. Find index of the row containing maximum number of 1’s in a binary matrix
  28. Travelling Salesman Problem using Branch and Bound
  29. Collect maximum points in a matrix by satisfying given constraints
  30. Count number of paths in a matrix with given cost to reach destination cell
  31. Find longest sequence formed by adjacent numbers in the matrix
  32. Find the minimum cost to reach last cell of the matrix from its first cell
  33. Matrix Chain Multiplication
  34. Find size of largest square sub-matrix of 1’s present in given binary matrix
  35. Chess Knight Problem – Find Shortest path from source to destination
  36. Find Duplicate rows in a binary matrix
  37. Print all possible solutions to N Queens problem
  38. Print all Possible Knight’s Tours in a chessboard
  39. Find Shortest Path in Maze
  40. Find Longest Possible Route in a Matrix
  41. Calculate size of the largest plus of 1’s in binary matrix
  42. Find the maximum value of M[c][d] – M[a][b] over all choices of indexes
  43. Find shortest distance of every cell from landmine in a Maze
  44. Find shortest route in a device to construct the given string


Thank you for being with us. 🙂


Leave a Reply

Notify of