Matrix – Interview Questions and Practice Problems

In this post, we have listed out commonly asked interview questions that use matrix data structure:

  1. Print matrix in spiral orderMedium
  2. Create a spiral matrix from a given arrayMedium
  3. Shift all matrix elements by 1 in spiral orderMedium
  4. Change all elements of row i and column j in a matrix to 0 if cell (i, j) is 0Medium
  5. Print diagonal elements of a matrix having a positive slopeMedium
  6. Replace all occurrences of 0 that are not surrounded by 1 in a binary matrixMedium
  7. In-place rotate matrix by 90 degrees in a clockwise directionEasy
  8. Count negative elements present in the sorted matrix in linear timeEasy
  9. Report all occurrences of an element in a row-wise and column-wise sorted matrix in linear timeMedium
  10. Check if a matrix is a Toeplitz or notEasy
  11. In-place rotate matrix by 180 degreesMedium
  12. Fill binary matrix with alternating rectangles of 0 and 1Medium
  13. Find all common elements present in each row of a matrixMedium
  14. Find common elements present in all rows of a matrixMedium
  15. Find the index of a row containing the maximum number of 1’s in a binary matrixHard
  16. Find the largest square submatrix which is surrounded by all 1’sMedium
  17. Print a spiral square matrix without using any extra spaceHard
  18. Young Tableau | Insert, Search, Extract-Min, Delete, ReplaceHard
  19. Replace all occurrences of 0 that are surrounded by 1 in a binary matrixMedium
  20. Find the area of the largest rectangle of 1’s in a binary matrixHard
  21. Find maximum value of M[c][d] – M[a][b] over all choices of indexesMedium
  22. Sort an array using Young tableauHard
  23. Print all possible solutions to N–Queens problemHard
  24. Print all possible Knight’s tours on a chessboardHard
  25. Find the shortest path in a mazeMedium
  26. Find the longest possible route in a matrixMedium
  27. Find the path from source to destination in a matrix that satisfies given constraintsMedium
  28. Find the total number of unique paths in a maze from source to destinationMedium
  29. Magnet PuzzleHard
  30. Find all paths from the first cell to the last cell of a matrixMedium
  31. Print all shortest routes in a rectangular gridMedium
  32. Find the shortest route in a device to construct a given stringMedium
  33. Find all occurrences of the given string in a character matrixHard
  34. Construct an ancestor matrix from a binary treeEasy
  35. Construct a binary tree from an ancestor matrixHard
  36. Find the size of the largest square submatrix of 1’s present in a binary matrixMedium
  37. Matrix Chain Multiplication using Dynamic ProgrammingHard
  38. Find minimum cost to reach the last cell of a matrix from its first cellMedium
  39. Find the longest sequence formed by adjacent numbers in the matrixMedium
  40. Count the number of paths in a matrix with a given cost to reach the destination cellMedium
  41. Collect maximum points in a matrix by satisfying given constraintsHard
  42. Find the number of ways to fill an N × 4 matrix with 1 × 4 tilesMedium
  43. Ways to reach the bottom-right corner of a matrix with exactly k turns allowedHard
  44. Calculate the minimum cost to reach the destination city from the source cityMedium
  45. Find the probability that a person is alive after taking n steps on an islandMedium
  46. Maximum Length Snake SequenceMedium
  47. Calculate the size of the largest plus of 1’s in a binary matrixHard
  48. Count all paths in a matrix from the first cell to the last cellEasy
  49. Calculate the sum of all elements in a submatrix in constant timeMedium
  50. Find maximum sum K × K submatrix in a given M × N matrixHard
  51. Find maximum sum submatrix present in a matrixMedium
  52. Find the length of the longest path in a matrix with consecutive charactersMedium
  53. Collect maximum value of coins in a matrixHard
  54. Transitive closure of a graphEasy
  55. All-Pairs Shortest Paths – Floyd Warshall AlgorithmEasy
  56. Determine a negative-weight cycle in a graphMedium
  57. Merge M sorted lists each containing N elementsHard
  58. Chess Knight Problem | Find the shortest path from source to destinationHard
  59. Shortest path in a maze – Lee AlgorithmMedium
  60. Find the shortest safe route in a field with sensors presentHard
  61. Flood Fill AlgorithmMedium
  62. Count number of islandsMedium
  63. Find the shortest path from source to destination in a matrix that satisfies given constraintsHard
  64. Find minimum passes required to convert all negative values in a matrixHard
  65. Find the shortest distance of every cell from a landmine inside a mazeHard
  66. Find duplicate rows in a binary matrixMedium
  67. Generate a list of possible words from a character matrixHard

Rate this post

Average rating 4.81/5. Vote count: 74

No votes so far! Be the first to rate this post.

We are sorry that this post was not useful for you!

Tell us how we can improve this post?

Thanks for reading.

To share your code in the comments, please use our online compiler that supports C, C++, Java, Python, JavaScript, C#, PHP, and many more popular programming languages.

Like us? Refer us to your friends and support our growth. Happy coding :)


guest
0 Comments
Inline Feedbacks
View all comments
Do NOT follow this link or you will be banned from the site!