Tag: spiral matrix

  • 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…