Tag: matrix

  • Data Structures & Algorithms in Java – Matrix – Word Search

    Problem Given a n*n matrix containing characters, find if the given word can be found in any direction For example , The output for above problem is true since the word ABCGK can be found in the matrix. Try out the solution here: https://leetcode.com/problems/word-search/ Solution: The solution to this problem is backtracking You start with…

  • Data Structures & Algorithms in Java – Matrix – Spiral Matrix

    Problem: Given a matrix , collect the elements in the matrix in a spiral direction clockwise and return them as a list. For example: Consider the matrix [[1,2,3],[4,5,6],[7,8,9]] You need to traverse the matrix spirally like below: So the output is : [1,2,3,6,9,8,7,4,5] Try out the solution here: https://leetcode.com/problems/spiral-matrix/ Solution: Hint: Traverse right , then…

  • Data Structures & Algorithms in Java – Matrix – Set Matrix Zeroes

    Problem: Given a matrix , if any of its element is zero , make all the elements in both the row and column of the element to zero. For example: For the given matrix: [[1,1,1],[1,0,1],[1,1,1]] The second row second column has the value zero. So make all the values in the second row and second…